2012-04-30 38 views
1

如何在VB.NET中創建一個無限範圍的數組,並獲取包含變量的數量?在VB.NET中創建一個2D動態數組

我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 

非常感謝

回答

2

我覺得你的語法是錯誤的

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