Today I will show a simple example with the multidimensional array in C#.
You can read the documentation from Microsoft.
It is easier for a beginner to understand from a simple example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | using System; class MainClass { public static void Main (string[] args) { Console.WriteLine ("This is a multidimensional array with two dimension D1 and D2!"); int D1 = 5; int D2 = 3; // two dimensional array int[,] array_ex_001 = new int[D1, D2]; array_ex_001[1, 2] = 76; Console.WriteLine("array at 0,0 is " + array_ex_001[0,0]); Console.WriteLine("array at 1,2 is " + array_ex_001[1,2]); // two dimensional array int[,] array_ex_002 = {{1,2},{3,4}}; for (int i = 0; i < array_ex_002.GetLength(0); i++) { for (int j = 0; j < array_ex_002.GetLength(1); j++) { Console.WriteLine (array_ex_002[i,j]); } } // three dimensional array with sized 4,2,3 int[,,] array_ex_003 = new int[4, 2, 3]; array_ex_003[2, 1, 1] = 76; // use for to show values , default is 0 for (int a = 0; a < array_ex_003.GetLength(2); a++) { for (int b = 0; b < array_ex_003.GetLength(1); b++) { for (int c = 0; c < array_ex_003.GetLength(0); c++) { Console.Write(array_ex_003[c, b, a]); } Console.WriteLine(); } Console.WriteLine(); } } } |
You can see it on this website: