bool [,] - What does this syntax mean in c#? -
i found in legacy code following line:
protected bool[,] pixelschecked;
what [,]
mean here?
it's two-dimensional array.
in .net can have 2 types of arrays aren't single dimension:
multidimensional arrays:
int[,] a; // 2 dimensions int[,,] b; // 3 dimensions, , on
jagged arrays (arrays of arrays):
int[][] a; // array of arrays of ints int[][][] a; // array of arrays of arrays of ints
in both cases need initialize variable before using though.
usage different, in first case:
int value = a[1, 2]; // note comma, , single pair of brackets
in second case, need address each array separately:
int value = a[1][2]; // first [1] will return array, , take // 3rd element (0-based) of
also remember can initialize multidimensional array in 1 statement:
int[,] = new int[10, 20];
whereas single statement jagged array create single array full of null-references:
int[][] = new int[10][];
you need initialize elements of array corresponding array references, here's quick way linq in 1 statement:
int[][] a = enumerable.range(0, 10).select(new int[20]).toarray(); // 10 x 20
also see msdn page on subject more information.
fun fact: jitter produces faster code accessing jagged arrays multidimensional arrays, see this question more information.
Comments
Post a Comment