It's not only faster (because VB doesn't have to check whether it needs to
instantiate the object every time you reference a property), it's also much
safer and less confusing.
For example, the App Wizard will create MDI child forms for you with
Dim frm1 As New Form1
If you try to refer to a property of Form1 in your code (instead of frm1),
you'll create another new instance!
I generally avoid Dim ... As New ... entirely.
Jim Deutch
MS Dev MVP
I have been reading about the use of the new keyword. The documentation
suggest to use it in the set instead of in the dim statement because this
produce a faster code.
But I'm still seeing a lot of examples that use the new keyword in the dim
statement for collections.
Why ?
Is it true that the new keyword in the set statement produce faster code
that in the dim ?
Is it only true for objects, not for collections ?
Or Is the diference between both options insignificant ?
Thanks in advance ...
Gabriel E. C. Coy - Buenos Aires - Argentina
Member of:
Microsoft Site Developer Network Level II
WorldWide SQL Server User's Group (www.swynk.com/sswug)
----------