Page 105 - CSharp/C#
P. 105
Output:
1
6
3
3
9
Multi-dimensional arrays
Arrays can have more than one dimension. The following example creates a two-dimensional
array of ten rows and ten columns:
int[,] arr = new int[10, 10];
An array of three dimensions:
int[,,] arr = new int[10, 10, 10];
You can also initialize the array upon declaration:
int[,] arr = new int[4, 2] { {1, 1}, {2, 2}, {3, 3}, {4, 4} };
// Access a member of the multi-dimensional array:
Console.Out.WriteLine(arr[3, 1]); // 4
Jagged arrays
Jagged arrays are arrays that instead of primitive types, contain arrays (or other collections). It's
like an array of arrays - each array element contains another array.
They are similar to multidimensional arrays, but have a slight difference - as multidimensional
arrays are limited to a fixed number of rows and columns, with jagged arrays, every row can have
a different number of columns.
Declaring a jagged array
For example, declaring a jagged array with 8 columns:
int[][] a = new int[8][];
The second [] is initialized without a number. To initialize the sub arrays, you would need to do
that separately:
for (int i = 0; i < a.length; i++)
{
a[i] = new int[10];
}
https://riptutorial.com/ 51

