What is the difference between these statements

  • Thread starter Thread starter Mat
  • Start date Start date
One looks cooler and the C# guys won't give you grief ;-) Other than that,
nothing.
 
HI
I might be wrong but as far as know
Dim s() as string
can have an initial bounds ie Dim s(5) as string at design time
when you know the size of the array
and Dim s as string() can not. You would need to use the
redim method at runtime to set the bounds of the array
You can also use redim on Dim s() as string as well

Cheers
James
 
* "Mat said:
Dim s() as string
Dim s as string()

Semantically, there is no difference. Both statements will create a
string array variable. I prefer the 1st version, but that's personal
preference.
 
Hi Mat,

In addition to Herfried,

I think most people will put the () after the first after a while when using
VB.net

And that because
dim a as string(10) cannot
While
dim a(10) as string is valid.

And therefore when you decide afterwards to make it a fixed array, you have
not to delete those () at the end and to put them at the first.

:-))

Just my thought,

Cor
 
Mat,
As the others have pointed out, there is no real difference on your two
statements.

Where the () are important is when you are defining return types.

Public Function StringArray() As String()
End Function

You need the () on the String, as that says the function is returning a
String Array.

Or if you are mixing multiple variables on a single Dim.

"a" is a single string, while "s" is an array in the following statement:
Dim a, s() as string

While both "a" & "s" are arrays in the following statement:
Dim a, s as string()

As the others have suggested I prefer the first "s()" unless I am required
to use the second (function & property types).

Hope this helps
Jay
 
Back
Top