views:

2635

answers:

6

I am looking for the VB.NET equivalent of

var strings = new string[] {"abc", "def", "ghi"};
+1  A: 
Dim strings As String() = New String() {"abc", "def", "ghi"}
David Mohundro
You don't need the new string() part for this to work
Pondidum
+1  A: 

Not a VB guy. But maybe something like this?

Dim strings = New String() {"abc", "def", "ghi"}

(About 25 seconds late...)

Tip: http://www.developerfusion.com/tools/convert/csharp-to-vb/

Jesper Palm
A: 

Dim strings As String() = {"abc", "def", "ghi"}

Steve Wright
+7  A: 
Dim strings() As String = {"abc", "def", "ghi"}
gfrizzle
+6  A: 

There are plenty of correct answers to this already now, but here's a "teach a guy to fish" version.

First create a tiny console app in C#:

class Test
{
    static void Main()
    {
        var strings = new string[] {"abc", "def", "ghi"};
    }
}

Compile it, keeping debug information:

csc /debug+ Test.cs

Run Reflector on it, and open up the Main method - then decompile to VB. You end up with:

Private Shared Sub Main()
    Dim strings As String() = New String() { "abc", "def", "ghi" }
End Sub

So we got to the same answer, but without actually knowing VB. That won't always work, and there are plenty of other conversion tools out there, but it's a good start. Definitely worth trying as a first port of call.

Jon Skeet
I agree that Reflector should be in every .NET developers tool belt. But for this it would be simpler to use the online converter at http://converter.telerik.com/
Jesper Palm
A: 

but if our data are not predefine then how we declare array in vb asp.net for web application ?

ArPAN sHAH