简体   繁体   中英

Jagged Array of 2d arrays error

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM