Resize a two-dimensional array

How to resize a two-dimensional array without affecting its value?

+3
source share
3 answers

Use ReDimwith modifier Preserve. VB.NET ensures that the original values ​​are not affected. Did not read the documentation. ReDim Preserveallows you to change the length of the last dimension of the array.

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

+6
source

As Adam said, you cannot resize 2D arrays dynamically. You can easily copy an existing array to a larger one, for example:

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

array.resize, .net 2 framework .

:

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

Source: https://habr.com/ru/post/1741411/


All Articles