The use of a three-dimensional rectangular array : Multi Dimensional Array « Data Structure « C# / CSharp Tutorial






using System;

class MainClass
{

  public static void Main()
  {
    int[,,] intArray = new int [10, 5, 3];

    intArray[1, 3, 2] = 3;
    intArray[4, 1, 2] = 9;

    Console.WriteLine("intArray.Rank (number of dimensions) = " + intArray.Rank);
    Console.WriteLine("intArray.Length (number of elements) = " + intArray.Length);

    for (int x = 0; x < intArray.GetLength(0); x++)
    {
      for (int y = 0; y < intArray.GetLength(1); y++)
      {
        for (int z = 0; z < intArray.GetLength(2); z++)
        {
          if (intArray[x, y, z] != 0)
          {
            Console.WriteLine("intArray[" + x + ", " + y + ", " + z +"] = " + intArray[x, y, z]);
          }
        }
      }
    }

  }

}
intArray.Rank (number of dimensions) = 3
intArray.Length (number of elements) = 150
intArray[1, 3, 2] = 3
intArray[4, 1, 2] = 9








11.6.Multi Dimensional Array
11.6.1.Declare, create, and initialize the rectangular array
11.6.2.Declaring a Two-Dimensional Array
11.6.3.Initializing a Two-Dimensional Array of Integers
11.6.4.Use Foreach statement to loop through Rectangular Array
11.6.5.Initialize a two-dimensional array
11.6.6.A two-dimensional array
11.6.7.Sum the values on a diagonal of a 3x3x3 matrix
11.6.8.Use foreach on a two-dimensional array.
11.6.9.The use of a three-dimensional rectangular array
11.6.10.Initialize multidimensional arrays in declaration
11.6.11.Use a single for loop to assign a two-dimensional array
11.6.12.Declaring a Jagged Array
11.6.13.Initializing a Jagged Array
11.6.14.Retrieving a Particular Dimension's Size
11.6.15.Test Single Dimension Array and Multi Dimension Array
11.6.16.Foreach with two dimensional array