Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing a two dimensional Array

How can I resize the two dimensional array size without affecting its value?

like image 207
Mark Avatar asked Dec 28 '22 19:12

Mark


2 Answers

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.

like image 192
Adam Maras Avatar answered Dec 31 '22 09:12

Adam Maras


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)
like image 42
invert Avatar answered Dec 31 '22 07:12

invert