How to initialize int [] []?

In C # how to initialize

int[][] test;

Instead, I do not want to use int[,]. I ask specifically how to initialize above. Obvious = int[1][1]does not work. I tried several different ways with no luck, and [] [], unfortunately, may not be available for Google (if this is not possible !?)

+4
source share
4 answers

He called jagged arrays if you want google this.

Basically, you can initialize the first dimension in the traditional way:

int[][] test = new int[23][];

And you manually initialize the rest:

for (int i = 0; i < test.Length; ++i)
    test[i] = new int[42];
+18
source

To initialize an array of an array, you need a for loop.

int[][] test = new int[N][];

for (int i = 0; i < test.Length; i ++)
   test[i] = new int [M];
+5
source
int[][] scores = new int[5][];
+3

Jagged Array. , " ", :

int[][] foo = new int[3][];

foo[0] = new int[2];
...
+3

All Articles