Jonathan Edgardo
Jonathan Edgardo

Reputation: 513

Make an 2D Dynamic Array in VB.NET

How i can make an array with unlimited range in VB.NET and also get the number of variables containing?

I tryed:

Dim _items(,) As String
_items(0, 0) = "hy"
        _items(0, 1) = "hello"
        _items(1, 0) = "bye"
        _items(1, 1) = "bye2"

        MsgBox(_items.GetLength(1)) 'But i cant get the length

Many Thanks

Upvotes: 1

Views: 1198

Answers (1)

kbvishnu
kbvishnu

Reputation: 15630

I think your syntax is wrong

Dim n As Integer = 2
Dim str As String(,) = New String(n - 1, n - 1) {}

 MsgBox(_items.GetLength(1)) //if n is 3 then this will return 3

    Dim n,m As Integer 
     n=3,m=2
    Dim str As String(,) = New String(n - 1, m - 1) {}

 MsgBox(_items.GetLength(1)) //  return 2
 MsgBox(_items.GetLength(1)) //  return 3

Upvotes: 2

Related Questions