I have this code:
Module Module1
Dim x As Integer = 1
Dim y As Integer = 1
Dim arr(x, y) As String
Sub Main()
x += 2
y += 3
For ix = 0 To x
For iy = 0 To y
arr(ix, iy) = String.Format("{0}:{1}", ix, iy)
Next
Next
For ix = 0 To x
For iy = 0 To y
Console.WriteLine(arr(ix, iy))
Next
Next
Console.Read()
End Sub
End Module
And with it I’m trying to change the upper bound of array dimensions. But I get this error:”Index was outside the bounds of the array”. What I’m doing wrong?
You can’t change the upper-bound of an array like that in .NET. If you need a dynamically sized Array I’d suggest looking at
Listas it allows you to do all of this.You’ll want to do something like:
To convert this to a 2-D Array:
From 2-D to List(Of List(Of String))