English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Requesting answers that will be intuitive to a programming semi-illiterate.

In .NET programming speak (in VB context, if/where it matters), what is meant by:

- (to) cast

- reflection

In the (instructional) phrase "cast to an interface that the type implements", what is meant by:

- interface

- type

In noob-speak, what would the entire phrase mean?

And what is meant by "strong-typed (reflection)"? What about "not-strong-typed"?

Other terms needing clarification:

- form control ID

- business object

- business object property name

I'll choose a best answer within one day's time.

Thanks!!

Scott

2007-09-09 20:17:27 · 1 answers · asked by SardonicMacaroni 5 in Computers & Internet Programming & Design

1 answers

To use a variable in a program you must first dimension (define) the name of the variable and what type of data it (the variable) will hold). The Dim command tells teh compilier to allocate an amount of memory and referr to it by a name you define.

There are several types of data which a variable may hold for example letters or numbers. Also when defining a numeric variable you may also define how large a number may be represented and its precision. So real numbers (with decimal points) have a data type called double, integers (no decimals) have an integer data type

So you define a Double variable type called myDbl to hold numbers like 3.1415 while an Integer data type called myInt may only represent numbers like 100 or 3.

Dim myDbl as Double
Dim myInt as Integer

myDbl = 3.1415 ' assign a value to the double data type

myInt = myDbl


CASTING:

Casting is just a fancy way of saying data will be convertd from one data type to another. The abov code I assigned 3.1415 to a double variable type which can represent decimals. The next line I am trying to assign data of one type into another type. (double into an integer) . Since myInt can only represent integers the decimals contained in myDbl are stripped away as the value of myDbl is assigned to myInt.

Type casting happens for you automatically in VB. You can assign data or one type into another without having to call a special function or method to do so. The problem withthis is that you may get unintended results if you do not cond=sider the ramifications of casting when loosing precision. in the above example the value of pi 3.1415 loading in the double data type looses all of its decimals when assigned to an integer value thus the value of pi 3.1415 becomes 3 in the variable myInt. Now going from an integer to a double is not an issue a value of myInt = 100 when type cast into a double will become 100.00


Casting is not limited to numbers of characters, It is possible to assign an object like a textbox into a variable of type object then later on assign a lablebox into the object variable

Dim myTxtBx as New Textbox
dim myLbl as New Lable
Dim myObj as Object

myObj = myTxt
myObj = myLbl

The TextBox and lable are interfaces called controls and are placed on a form. These controls allow the program to interact with the user to receive user input via teh textbox or to display data via a label.

Both of these ontrols have a text property which is used to display or read characters(strings) which are displayed in them. Strings are a series of characters and are a data type used to store word and sentences typically.
The text properties of these controls expect to deal with strings. however you can display the contents of a Double data type in a text box

myTxtBox.text = myDbl ' 3.1415
or
myLbl.text = myDbl

VB knows that you want to display the 3.1415 as a string in the text box and performs a type cast.

myTxtBox.Text = myDbl.ToString

Obviously this is a supported type cast as numeric data is usually displayed to a user. However an unsupported typecast could be

myLbl = myTextBox

you intext to copy what is displayed in the text box and show it in the lable. A text box cannot be converted to a label.
You would have to assign a property to another like property

myLbl.Text = myTxtBox.Text
This assigns the string in the text box into the lables text property which is ex[pecting a string sata type

2007-09-10 12:33:03 · answer #1 · answered by MarkG 7 · 1 0

fedest.com, questions and answers