Monday, March 2, 2015

multidimensional and jagged arrays in C#

This suggests that the three varieties of C# arrays are single-dimensional, multidimensional, and jagged. I offers that the multidimensionals are made and used like so:

int[,] array = { { 1, 2, 3 }, { 4, 5, 6 } };
var foo = array[1,2];

 
 

...and the jagged like so:

int[][] array = new int[6][];
array[0] = new int[4] { 1, 2, 3, 4 };
var foo = array[0][1];

 
 

The distinction being that a multidimensional array is an array of arrays where every "child" array will have the same number of slots. An example, might be an array of 4 arrays of 3 slots each. The jagged arrays do not have this restraint on their kiddos.

No comments:

Post a Comment