> DoSomething(New String()={"Hello","World","Goodbye"})
Later...
Hmm, just done some experiments with ParamArray and discovered an
interesting side effect:
Dim MyWords() As String = {"Hello", "World", "Goodbye"}
Something(MyWords)
Sub Something(ByVal ParamArray MyWords() As String)
Dim x As String
For Each Word As String In MyWords
x &= Word & " "
Next
End Sub
The thing that surprised me about this is that I kind of expected VB.NET to
end up with MyWords() inside the sub containing just one item but this item
was itself an array. I have vague memories of this happening in VB6.
However, something different happens in that although only one parameter is
being passed, ParamArray MyWords() As String ends up containing 3 items
which is fine. So it means that when you use ParamArray you can either pass
a series of strings (in this example) or a single string array.
Taking it further:
Something(MyWords, "Wibble", "Wobble") generates a compile error complaining
that:
c:\inetpub\wwwroot\Hops\WebForm1.aspx.vb(32): Value of type '1-dimensional
array of String' cannot be converted to 'String'.
Which is kind of expected.
I assume this is intentional and programmed this way and not an accident of
some kind.
Cheers, Rob.
PS. Doesn't answer my original question though of whether you can create and
initialise arrays on the fly.
|