I was just wondering if there is any difference between the two different new object initializers or is it just syntactic sugar.
So is:
Dim _StreamReader as New Streamreader(mystream)
and different to:
Dim _StreamReader as Streamreader = new streamreader(mystream)
Is there any difference under the hood? or are they both the same? Which one do you prefer to use?
In VB.NET, they’re identical. The
As Newvariant is canonical.In VB6, their semantics actually differed (apart form the obvious fact that VB6 didn’t allow assignments in declarations): the
As Newvariant would create an object that could never beNothing. Rather, the runtime would ensure that the object was always properly initialized before each access to it.