String Array

  • Thread starter Thread starter C CORDON
  • Start date Start date
C

C CORDON

Is there a way to declare AND in the same line assign values to a string
array?

TIA
 
C CORDON said:
Is there a way to declare AND in the same line assign values to a string
array?

\\\
Dim s() As String = {"Bla", "Foo", "Goo"}
///
 
Herfried K. Wagner said:
\\\
Dim s() As String = {"Bla", "Foo", "Goo"}
///

Am I the only one that does this differently (with the same result)???

Dim s As String() = New String() { "Bla", "Foo", "Goo" }

???

Maybe so :P

Mythran
 
Mythran said:
Am I the only one that does this differently (with the same result)???

Dim s As String() = New String() { "Bla", "Foo", "Goo" }

I prefer to type less characters, but the code will produce the exact same
IL.
 
Would not his code create an array of string arrays? I don't think
that is the same.

Chris
 
Chris,

Chris Dunaway said:
Would not his code create an array of string arrays? I don't think
that is the same.

\\\
Dim astr1() As String = {"Foo", "Bar", "Baz"}
Dim astr2 As String() = {"Foo", "Bar", "Baz"}
Dim astr3() As String = New String() {"Foo", "Bar", "Baz"}
Dim astr4 As String() = New String() {"Foo", "Bar", "Baz"}
///

.... are semantically the same. All four lines will create one-dimensional
string arrays that contain three strings.
 
I misread the original post. I thought he had written:

Dim s() As String() = New String() = {"Foo", "Bar", "Baz"}

which will generate a compile time error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top