asked on # Storing a 2-dimensional array within a 1-dimensional array

All I'm trying to do here is store a collection within a collection...the collection being arrays. My problem is the syntax. I have built the 2-dimensional array, now I wish to add it to the 1-dimensional array but not sure how to do it. Here is my code below.

Dim idx As Integer = 0

Dim arr1() As String

Dim arr2(,) As String

Redim Preserve arr1(idx)

For x As Integer = 0 To 14

Redim Preserve arr2(x, y)

For y As Integer = 0 To 9

Redim Preserve arr2(x, y)

arr2(x, y) = "Test " & x & " and " & y

Next

Next

arr1(idx) = arr2

I'm getting an error where I assign arr2 to arr1. It says "Value of type 2-dimensional array of String cannot be converted to String". I also tried this:

arr1(idx) = arr2()

The above syntax gave me the error "Number of indices is less than the number of dimensions of the indexed array".

Dim idx As Integer = 0

Dim arr1() As String

Dim arr2(,) As String

Redim Preserve arr1(idx)

For x As Integer = 0 To 14

Redim Preserve arr2(x, y)

For y As Integer = 0 To 9

Redim Preserve arr2(x, y)

arr2(x, y) = "Test " & x & " and " & y

Next

Next

arr1(idx) = arr2

I'm getting an error where I assign arr2 to arr1. It says "Value of type 2-dimensional array of String cannot be converted to String". I also tried this:

arr1(idx) = arr2()

The above syntax gave me the error "Number of indices is less than the number of dimensions of the indexed array".

Visual Basic.NET

View this solution by signing up for a free trial.

Members can start a 7-Day free trial and enjoy unlimited access to the platform.

Thanks ChloesDad...I didn't use that exact code but it did jar my memory and now I got it working.