Konrad Konrad - 5 months ago 8
Vb.net Question

VB MyVar() as String vs MyVar as String()

This may be obvious, but I can't find anything about it in my searching.

What is the difference between

MyVar() as String


and

MyVar as String()


I realise the first is an array made up of strings. But what is the second? What is a String Array? Or is it just the same?

Answer

They both will produce the exact same result (create a string array) as in the duplicate post that sstan referred to.

But there's only one difference I can think of, which is: you can directly specify the number of elements that the array will consist of when using the first method..

Dim MyVar() As String 'An array of string (the number of elements aren't yet specified).
Dim MyVar As String() 'Same as above.
Dim MyVar(5) As String 'An array of string (consists of 6 elements).
Dim MyVar As String(5) 'Wrong (you'll get an error).

Hope that helps :)