VB.Net Initialising an array on the fly

Any reason not to do:

Dim someNames() as string = New String(){"Han", "Luke", "Leia"}

The only difference is type inference, as far as I can tell.

I've just checked, and VB 9 has implicitly typed arrays too:

Dim someNames() as string = { "Han", "Luke", "Leia" }

(This wouldn't work in VB 8 as far as I know, but the explicit version would. The implicit version is necessary for anonymous types, which are also new to VB 9.)


Dim somenames() As String = {"hello", "world"}

The following codes will work in VB 10:

Dim someNames = {"Hans", "Luke", "Lia"} 

http://msdn.microsoft.com/en-us/library/ee336123.aspx

Tags:

Vb.Net

Arrays