declaration statement question (VB6?)

bri189a

Well-known member
Joined
Sep 11, 2003
Messages
1,004
Location
VA
Ive been doing:

Dim x as SomeClass = new SomeClass(operators)

But I found accidently:

Dim x as New SomeClass(operators)

Is the first or second preferred .NET syntax...Ive been using the first since its similiar to C# syntax. Is one of them VB6?
 
Either work fine in VB.Net in fact all the following have the same end result
Code:
Dim a As Object
a = New Object

Dim b As Object = New Object

Dim c As New Object
You found that in good quality VB6 code the first was the prefered method as doing the dim blah as new thing syntax in VB6 behaved differently to declaring and initialising on two lines (more importantly the difference was quite subtle until you were hit by a nasty bug or two)
 
Back
Top