Developers who have mastered arrays, and want to put some complexity into their multi-dimensional arrays, can mix jagged and rectangular arrays. [7] Here is an example.
int[][,] MessyArray = new int [3][,] { new int[,] { {1,3}, {5,7} }, new int[,] { {0,2}, {4,6}, {8,10} }, new int[,] { {11,22,33}, {77,88,99} } }; This statement creates an int array called MessyArray , which is an array of two arrays. The first is an array of size 3 “ call them 3a , 3b , and 3c . 3a is a 2D array containing 2 rows of 2 cells each. 3b is a 2D array containing 3 rows of 2 cells each, and 2c is a 2D array of 2 rows of 3 cells each. Figure 12.6 shows what MessyArray looks like. Figure 12.6. MessyArray .
As an example, you can access the cell containing the value 22 via the expression: MessyArray[2][0,1] Despite the increased complexity of C# arrays, no matter how you declare them, arrays in C# can store only elements of the same type (as with Java arrays). |