Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I've 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...I've been using the first since it's similiar to C# syntax. Is one of them VB6?

  • Administrators
Posted

Either work fine in VB.Net in fact all the following have the same end result

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)

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...