The equivalent in C# is the same if you are using jagged arrays:
private Square[][][] sheets;
public Square[][] GetSheet(int index)
{
return sheets[index];
}
If you have a multi-dimensional array there's not a simple way to get two of the three dimensions. The best you can do is recreate an array:
private Square[,,] sheets;
public Square[,] GetSheet(int index)
{
int x = sheets.GetLength(0);
int y = sheets.GetLength(1);
Square[,] sheet = new Square[x,y];
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
sheet[i,j] = sheets[i,z,index];
return sheet;
}
How do I initialize a Square[4][4][4]?
You can either loop and initialize each dimension:
for(int i = 0; i < 4; i++)
{
sheets[i] = new Square[4][];
for(int j = 0; j < 4; j++)
{
sheets[i][j] = new Square[4];
}
}
(Note that if Square is a reference type, then you also need to initialize each Square[i][j][k] to a value, otherwise it will be null)
or use array initialization syntax;
sheets = new Square[4][][]
{
new Square[4][] {new Square[4], new Square[4], new Square[4], new Square[4],},
new Square[4][] {new Square[4], new Square[4], new Square[4], new Square[4],},
new Square[4][] {new Square[4], new Square[4], new Square[4], new Square[4],},
new Square[4][] {new Square[4], new Square[4], new Square[4], new Square[4],},
};
Obviously, looping scales much more easily that initialization syntax.
int[,,] array3D = new int[x, y, z];is a 3d array in c#[][,]Square[][,]may be the cleanest structure.