0

How can we initialize a multidimensional array without pre-existing values? Only the third one is correct, but it works with pre-existing values. I would like my multidimensional array to contain 10 or 20 values, and add them later on with numbers[y][x] :

int[][] numbers = new int[10][];
//List<int[]> numbers = new List<int[]>();
//int[10][]{ new int[]{}};
//correct :  { new int[] {1, 2}, new int[] {3, 4, 5} };
numbers[0][0] = 58;

Would you know how to do this? (I don't know if [,] is the same as [][] by the way)

Thanks

2 Answers 2

1

Would you know how to do this? (I don't know if [,] is the same as [][] by the way) there are not the some as int[][] test = new int[10][]; is called a jagged array (array of arrays) and int[,] is a fixed array

just declare your array as the following

 int[,] test = new int[10,30];    
test[0,1] = 10;
test[1,2] = 20;
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much Julie Shannon
1

You can try initiating values this way, it is one way to create jagged-array

int[][] test = new int[10][];
test[0] = new int[20];
test[1] = new int[30];
test[2] = new[] { 3, 4, 5 };

test[0][1] = 10;
test[1][2] = 20;

1 Comment

Thank you very much AppDeveloper

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.