[RESOLVED] This array doesn't work.
The book example of this array has an error when I try to run it.
int[][] x = { { 2, 3 }, { 4, 5 }, { 6, 7 } };
error:
Array initializers can only be used in a variable or field initializer. Try using a new expression instead.
Ok, after looking at the MSDN, I think it should look like:
int[,] x = new int[3, 2];
Is the book example above(up top) even correct?
Re: This array doesn't work.
Which one are you wanting? The Multidimensional array or the Jagged array? The first one with the error looks more suited to a mutlidimensional array, which is what you declared in the second one:
PHP Code:
int[,] x = new int[3, 2] { {2, 3}, {4, 5}, {6, 7} };
?
EDIT: Also, jagged arrays would be declared like so:
PHP Code:
int[][] x = new int[][] { new int[] {2,3,4}, new int[] {5,6,7} };
chem
Re: This array doesn't work.
I just wanted to be sure that the first one is defenitely an error before I go marking in the book to fix it.
I will replace it with the second line that I believe to be the correct version of the multidimensional array.
In your line:
int[][] x = new int[][] { new int[] {2,3,4}, new int[] {5,6,7} };
You are only initializing part of the jagged array? That is ok to do? What happens with the empty index when the array gets used?
Re: This array doesn't work.
Ok, it defenitely was incorrect. It has to have the new.