VB Multi-Dimensional Arrays


Multidimensional arrays are also called rectangular arrays

Example

Module arraydc
Sub, Main()
' an array with 5 rows and 2 columns
Dim a(,)    As Integer = {{0, 0}, {1, 2}, {2, 4}, {3, 6}, {4, 8}}
Dim i, j    As Integer
 ' output each array element's value
For i = 0    To 4
For j = 0    To 1
              Console.WriteLine("a[{0},{1}] = {2}", i, j, a(i, j))
 Next j
      Next i
      Console.ReadKey()
End Sub
End Module
Output
a[0,0]: 0
a[0,1]: 0
a[1,0]: 1
a[1,1]: 2
a[2,0]: 2
a[2,1]: 4
a[3,0]: 3
a[3,1]: 6
a[4,0]: 4
a[4,1]: 8

Share this article on