Question

I try to write an int-Array, but

why I can't write:

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

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

Was it helpful?

Solution

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 were a 3-dimensional array instead of a jagged array you could do:

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

OTHER TIPS

From Jagged Arrays (C# Programming Guide)

Before you can use a jagged array, its elements must be initialized.

[5][5,5] means your jagged array has 5 array which all they are two-dimensional and their dimensions are 5 and 5.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top