Question Is this statement from VB6 true of VB.NET?

Cep

Member
Joined
Apr 29, 2008
Messages
11
Programming Experience
1-3
Hi I was just sent an article regarding optimisation of code by a colleague. The article is actually for VB6 (something I think they overlooked) but one statement in it has got me to wondering.

Don't Dim .. As New

Dim obj As MyClass
Set obj = New MyClass

Why write 2 lines when you can just say Dim obj As New MyClass?

Never Dim anything As New if you're concerned about speed. VB6 will treat such a variable as an auto-instantiated variable. Every time you use it, VB will check if it should be instantiated. This will cost you some extra CPU cycles.

This comes from http://www.aivosto.com/vbtips/not-optimize.html

I was just wondering if this statement if true, is also true of VB.NET?

Thanks :)
 
is also true of VB.NET?
No, it is not. Dim x As New type is recommeded. Using the New keyword in VB.Net will create the instance, this was not true with VB6.
 
Back
Top