我正在尝试将项目添加到 Array 2d。
但这会引发异常,消息如下:Redim only can change the dimension which is more to the right
' Create Array 2D
Dim MyArray As String(,) = _
{{"Item 0,0", "Item 0,1"}, {"Item 1,0", "Item 1,1"}, {"Item 2,0", "Item 2,1"}}
' Add Item
ReDim Preserve MyArray(MyArray.GetUpperBound(0)+1, MyArray.GetUpperBound(1)+1)
MyArray(MyArray.GetUpperBound(0), MyArray.GetUpperBound(1) - 1) = "Item 3,0"
MyArray(MyArray.GetUpperBound(0), MyArray.GetUpperBound(1)) = "Item 3,1"
我做错了什么?
另外......我可以像这样同时设置两个维度?:
ReDim Preserve MyArray(MyArray.GetUpperBound(0)+1, MyArray.GetUpperBound(1)+1)
MyArray(lastitem) = {"Item 3,0", "Item 3,1"}
更新:
好吧......否则尝试一下,我不明白,代码不起作用:
' Add Item
Dim MyArray2(MyArray.GetUpperBound(0) + 1, MyArray.GetUpperBound(1) + 1)(,) As String
MyArray.CopyTo(MyArray2, 0)
MyArray2(MyArray2.GetUpperBound(0), MyArray2.GetUpperBound(1) - 1) = "Item 3,0"
MyArray2(MyArray2.GetUpperBound(0), MyArray2.GetUpperBound(1)) = "Item 3,1"