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:

  1. multidimensional arrays:

    int[,] a;    // 2 dimensions int[,,] b;   // 3 dimensions, , on 
  2. 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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -