"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
<im****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...I do not think so, you are creating a button that references the
original button which also takes the original button's type.
So if I am creating a variable and assigning it a value, does that mean I
don't need to use the "as", such as:
Dim ktr = 135
or
Dim name = "Franklin"
or
Can I change:
Dim oGrid as DataGrid =
CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DataGrid1"),DataGrid)
to
Dim oGrid =
CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DataGrid1"),DataGrid)
Not that I would, just trying to see what you can and cannot do and why.
Thanks,
Tom
Ok, to clear things up for you guys.
Dim value1 As MyObject = New MyObject()
Dim value2 As MyObject = value1
Dim value3 = CType(value1, MyObject)
Variable Variable Type Reference/Value Type
value1 MyObject MyObject
value2 MyObject MyObject
value3 Object MyObject
value1 can and does reference MyObject. It can ONLY reference a MyObject
object.
value2 can and does reference MyObject. It can ONLY reference a MyObject
object.
value3 can and does reference MyObject. It can reference any reference or
value.
value1 contains a reference that was created and stored in the value1
variable.
value2 is declared and then set to the same reference that value1
references.
value3 is declared AS OBJECT and is set to reference the same reference that
value1 references.
They are all valid, but note that value3 can be contain a reference or value
to anything else.
So, the following is also valid (beware of doing this, this is not very good
technique and is only being shown to you for your knowledge):
Dim value1 As MyObject = New MyObject()
Dim value3 = value1
value3 = "Test"
value3 = 1234
value3 = New Button()
value3 = New DataGrid()
value3 = New System.Data.OleDbConnection()
All the lines above can happen in the same routine in the same order and
shouldn't fail. That is why it is best to declare all variables with the
types that will be used. Can you see the dangers?
Dim myInt = 123
myInt = Request("myInt")
Dim x As Integer = myInt
Note the above, myInt is set to 123 and you'd probably expect myInt to be an
integer value. When you call Request (pulling a variable from the
querystring in ASP.Net) it returns a string value. What if that string
value wasn't a number? This is a logic error anyways, but using it to prove
my point. When you set x equal to myInt (now contains a string that isn't a
number), the program would throw an exception.
Anywho, that is why declaring without the data type works but should be used
extremely rarely and with caution.
Mythran