|
-
Aug 4th, 2004, 06:07 PM
#1
Thread Starter
Registered User
late binding?
what is better?
VB Code:
dim a as myOBJ = new myOBJ()
or
-
Aug 4th, 2004, 06:15 PM
#2
I wonder how many charact
I don't know of any particular difference. But what you are referring to is not late-binding as most people express it.
I think what you were concerned about is perhaps an unnecessary boxing operation, or maybe even an implicit conversion that Option Strict wouldn't allow.
However, Objects are just reference containers to other declared types, so you can do something as bizzare as this:
VB Code:
Dim x As New Object
Dim y As Integer = 5
x = y
MessageBox.Show(x.ToString)
Dim z As New ArrayList
x = z
MessageBox.Show(x.ToString)
-
Aug 5th, 2004, 02:10 PM
#3
Lively Member
The second statement is one of the shorthand techniques introduced in VB.NET, just like they introduced direct assignment and other stuff.
Anyway you may use late initializing for objects when you want to use it several times:
VB Code:
Dim myObj as someType
myObj = New someType()
muObj.property1 = value1a
muObj.property2 = value2a
myObjCollectionA.Add(myObj)
myObj = New someType()
muObj.property1 = value1b
muObj.property2 = value2b
myObjCollectionB.Add(myObj)
.
.
.
Do you think my life is easy?
Do you think it's good to win?
do you think it's nice to kill?
Do you think learning is a must?
Do you think computers are nothing?
Do you think this post is stupid?
Do ypu think we're really humen?
DO YOU THINK IT'S GOOD TO THINK AT ALL? ? ? ! ! !
-
Aug 5th, 2004, 02:33 PM
#4
Sleep mode
-
Aug 6th, 2004, 12:46 AM
#5
Latebinding is when an object is declared as a generic type instead of a strong type. Latebinding slows performance because all of the type checking must be done at runtime instead of during compile.
VB Code:
'This is latebinding
Dim obj As Object
obj=New Form()
'This is still latebinding is the same as the above
Dim obj As Object=New Form()
'This is NOT latebinding and is better code
Dim obj As Form
obj=New Form()
Dim obj As Form=New Form()
'Again this is the same as the above
Dim obj As New Form()
The difference being that the first example, the latebinding example declares the object as the generic type Object but in fact stores a more specific type in it later. The fact that there is some runtime type checking makes this latebinding.
The second example declares the variable as type Form because it will in fact hold an object of that type.
-
Aug 6th, 2004, 03:10 AM
#6
Thread Starter
Registered User
so is
dim obj as new form()
late binding or not? by saying it's same as above, it's still unclear...
-
Aug 6th, 2004, 07:44 AM
#7
Frenzied Member
No, it's not late binding. "Same as above" refers to the statement immediately above the last one.
The idea is that if you dim something as a specific type, it's early binding. If you don't, it's late binding.
-
Aug 6th, 2004, 08:08 AM
#8
I wonder how many charact
Originally posted by marvinklein
so is
dim obj as new form()
late binding or not? by saying it's same as above, it's still unclear...
It's not late-binding, and neither is the two code snippets you supplied at the top of the thread.
-
Aug 6th, 2004, 11:22 PM
#9
Originally posted by salvelinus
No, it's not late binding. "Same as above" refers to the statement immediately above the last one.
The idea is that if you dim something as a specific type, it's early binding. If you don't, it's late binding.
Originally posted by nemaroller
It's not late-binding, and neither is the two code snippets you supplied at the top of the thread.
What they said.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|