Multi-Dimensional Arrays


Rectangular Arrays - These are really 2 dimensional. The number of rows is identical to the number of columns.
Jagged Arrays - These are not really 2 dimensional and represent a 1 dimensional array of 1 dimensional arrays. Each element in the main array can hold an array of varying length.



Arrays with mutiple dimensions are also referred to as jagged arrays.


string[,] asMulti = new string[5,5]; 

Dim asMulti(5,5) As String 


GetLowerBound - Get the upper bound of the specified dimension. Starting at the number 0.
GetUpperBound - Get the lower bound of the specified dimension. Starting at the number 0.


Dim asTableValues(10, 200) As String 
Dim asTableValues As String()

asTableValues.GetUpperBound(0) = 10
asTableValues.GetUpperBound(1) = 200

Dim icolumnnumber As Integer 
For icolumnnumber = 0 To asArrayName.GetUpperBound(0)

Next icolumnnumber

Dim irowcount As Integer 
For irowcount = 0 To asArrayName.GetUpperBound(1)

Next irowcount

Conceptually, a multidimensional array with two dimensions resembles a grid. A multidimensional array with three dimensions resembles a cube.


int[,] array2D = new int[2,3]; 
int[,] array2D2 = { {1, 2, 3}, {4, 5, 6} };



for (int i=0; i<2; i++) 
{
for (int j=0; j<3; j++)
{
array2D[i,j] = (i + 1) * (j + 1);
}
}


for (int i=0; i<2; i++) 
{
for (int j=0; j<3; j++)
{
System.Console.Write(array2D[i,j]);
}
System.Console.WriteLine();
}

int[] numbers = { 4, 5, 6, 1, 2, 3, -2, -1, 0 };
foreach (int i in numbers)
{
System.Console.Write("{0} ", i);
}



© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext