My problem is I want to initialize a multidimensional array declared like this:
int[][][] my3DArray;
However, the following code gives me an error on [sizeY][sizeZ]
saying it expected ',' or ']'.
void Set3DArraySize(int sizeX, int sizeY, int sizeZ)
{
my3DArray = new int[sizeX][sizeY][sizeZ];
}
When i declare the array like this though:
int[,,] my3DArray;
I am able to initialize it without any problems by doing it like this:
my3DArray = new int[sizeX,sizeY,sizeZ];
But then the problem becomes that if I try to get the length of one of the arrays I can't do for example my3DArray[x,y].Length
and am instead forced to pass all of the indexes together my3DArray[x,y,z]
.
So, is there any way I can initialize the array with it being declared as int[][][] my3DArray;
? Or will I have to store the sizes of the arrays elsewhere and use it like this int[,,] my3DArray;
?