Matt126
Matt126

Reputation: 997

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.

Upvotes: 4

Views: 147

Answers (2)

D Stanley
D Stanley

Reputation: 152511

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

Upvotes: 5

Soner G&#246;n&#252;l
Soner G&#246;n&#252;l

Reputation: 98740

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.

Upvotes: 2

Related Questions