Jagged Array error from 2d arrays

I'm trying to write int-array but

why i cant write:

int[][,] JaggedInt = new int[5][5,5];

and how can I write a similar Jagged int as above.

+3
source share
2 answers

For a jagged array, you need to initialize each array separately:

int[][,] JaggedInt = new int[5][,];
for(int i = 0; i < 5; i++)
    JaggedInt[i] = new int[5,5];

if it was a three-dimensional array instead of an array you could do:

int[,,] JaggedInt = new int[5,5,5];
+4
source

From Jagged Arrays (C# Programming Guide)

Before you can use an uneven array, its elements must be initialized.

[5][5,5]means that your gear array has an array 5that they are all two-dimensional, and their sizes 5and 5.

+2
source

All Articles