4

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.

1
  • If you know ahead of time that all of your arrays will have 5 elements, then perhaps you don't need a jagged array? new int[5,5,5]? Commented Feb 17, 2014 at 15:13

2 Answers 2

5

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];
Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.