Multidimensional arrays come in two varieties: rectangular and jagged.

Rectangular arrays are an n-dimensional block of memory, and jagged arrays are arrays of arrays.

Rectangular arrays are declared using commas to separate each dimension.

The following declares a rectangular two-dimensional array, where the dimensions are 3 by 3:

int[,] matrix = newint[3,3];

GetLength() method from array returns the length for a given dimension starting at 0.

for (inti = 0; i < matrix.GetLength(0); i++){ for (intj = 0; j < matrix.GetLength(1); j++){ matrix[i,j] = i * 3 + j; } }

A rectangular array can be initialized as follows:

int[,] matrix = newint[,]{ {0,1,2}, {3,4,5}, {6,7,8} };

Jagged arrays are declared using successive square brackets to represent each dimension.

The following code declares a jagged two-dimensional array, where the outermost dimension is 3:

int[][] matrix = newint[3][];

Each inner array can be an arbitrary length and must be created manually:

for (inti = 0; i < matrix.Length; i++) { matrix[i] = newint[3]; // Create inner array for (intj = 0; j < matrix[i].Length; j++) matrix[i][j] = i * 3 + j; }

A jagged array can be initialized as follows.

int[][] matrix = newint[][] { newint[] {0,1,2}, newint[] {3,4,5}, newint[] {6,7,8,9} };

- What is the output: Jagged Array Upper Bound?
- What is the output: Jagged Array Upper Bound One?
- What is the output: Jagged Array Upper Bound vs Length?
- What is the output: Jagged Array Length?
- What is the output: rectangular array length?