Error - Invalid rank specifier, 2d integer array

I am trying to declare and initialize a 2d array of integers, that will hold values associated with what will go where in a grid of objects.

The line of code that is giving me trouble is

int[,] gridInfo = new int [,] { {0,1,0,1,0}, {1,0,1,0,1,0}, {3,1,0,1,0}, {1,0,1,0,1,0}, {0,1,0,1,0,1} };

The error it is giving me is "Invalid rank specifier:expected ‘,’ or ‘]’ 3 times within the same line.

I am a begginer at c# so i’m sorry if this is a easily fixed problem.

I’ve never tried to initialize a multidimensional array in place, but if it works like that I’m pretty sure you have to specify the same amount of data for each diminsion. In some(2) you have 5 elements in the some(3) you have 6 elements.


After some searching it seems that it should be the problem.

Just make sure that each dimension has a clear element count.


int[,] gridInfo = new int [,] {