How to print a C # 3D gear array

From @Henk Holterman 's answer regarding C # 3 dimensional arrays (how do you print foos on the console:

Foo[][][] foos = new Foo[2][][];

for (int a = 0; a < foos.Length; a++)
{
  foos[a] = new Foo[3][];
  for (int b = 0; b < foos[a].Length; b++)
  {
     foos[a][b] = new Foo [4];

     for (int c = 0; c < foos[a][b].Length; c++)
        foos[a][b][c] = new Foo();
  }
}

Thanks.

+1
source share
1 answer

This is pretty easy to do. Use the three operators to cycle through each index to access each instance of Foos.

        for (int x = 0; x < foos.Length; x++) {
            for (int y = 0; y < foos[x].Length; y++) {
                for (int z = 0; z < foos[x][y].Length; z++) {
                    Console.WriteLine(foos[x][y][z].Member);
                }
            }
        }
+1
source

Source: https://habr.com/ru/post/1606659/


All Articles