문제

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.

도움이 되었습니까?

해결책

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];

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top