MultiDimensional Arrary in VB.NET
In this article you will learn how to declare mulitidimensional array in VB.NET.
An array is a collection of values of the same data type. Arrays have upper and lower bounds and the elements have to lie within those bounds. Each index number in an array is allocated individual memory space and therefore users must evade declaring arrays of larger size than required.
The rank value of the array is also known as the dimension of the array. Arrays which can have multiple dimensions are called multidimensional array. A common use of multidimensional arrays is to represent tables of values consisting of information arranged in rows and columns. To identify a particular table element, we must specify two indexes: The first (by convention) identifies the element's row and the second (by convention) identifies the element's column. Note that multidimensional arrays can have more than two dimensions.
The following code is an example of a multidimensional array:
Imports System.Text
Module Module1
Sub main()
Class multiarray
Private Shared Sub Main(ByVal args As String())
Dim sum As Integer = 0
Dim rowsum As Integer
Dim marray As Integer(,) = New Integer(1, 3) {{2, 2, 2, 2}, {3, 3, 3, 3}}
For row As Integer = 0 To 1
rowsum = 0
For col As Integer = 0 To 3
Console.WriteLine("{0}" & vbTab, marray(row, col))
rowsum = rowsum + marray(row, col)
Next
sum = sum + rowsum
Console.WriteLine(" = {0}" & vbTab, rowsum)
Console.WriteLine()
Next
Console.WriteLine(" the sum of the array is :{0}", sum)
Console.ReadLine()
End Sub
End Class
End Sub
End Module
OUTPUT