开发者

Resizing a two dimensional Array

开发者 https://www.devze.com 2022-12-26 21:07 出处:网络
How can I resize the two dimensional array size without affe开发者_开发知识库cting its value?Use ReDim with the Preserve modifier. VB.NET will make sure the original values are untouched. Didn\'t read

How can I resize the two dimensional array size without affe开发者_开发知识库cting its value?


Use ReDim with the Preserve modifier. VB.NET will make sure the original values are untouched. Didn't read the documentation right. ReDim Preserve will only allow you to change the length of the last dimension of the array.

You need to allocate a new array (with the correct size) and manually copy the elements from the first array to the second.


As Adam said, you can't resize 2D arrays dynamically. You can easily copy the existing array into a bigger one like so:

Dim smaller(1, 1) As Byte
Dim bigger(2, 2) As Byte
Array.Copy(smaller, bigger, smaller.length)


Try using array.resize if you are on .net 2 framework or above.

For example:

Dim MyArray() as string
Array.Resize(myarray,12)
0

精彩评论

暂无评论...
验证码 换一张
取 消