Three Dimensional Array in C#

In this article I will explain that how to create Three Dimensional Array .
  • 12775

The concept of Three dimension array. In a Three dimension array we need only one index to access the member of array. These types of arrays are used to store number of items of a predefined type. A multidimensional array is a series of arrays so that each array contains its own sub-array(s).

namespace demo_array

{

    class Program

    {   

        static void Main(string[] args)

        {

            // Create a three-dimensional array.

            int[, ,] 3D = new int[3, 5, 4];

            3D[0, 0, 0] = 1;

            3D[0, 1, 0] = 2;

            3D[0, 2, 0] = 3;

            3D[0, 3, 0] = 4;

            3D[0, 4, 0] = 5;

            3D[1, 1, 1] = 2;

            3D[2, 2, 2] = 3;

            3D[2, 2, 3] = 4;

 

            // Loop over each dimension's length.

            for (int i = 0; i < 3D.GetLength(2); i++)

            {

                for (int y = 0; y < 3D.GetLength(1); y++)

                {

                    for (int x = 0; x < 3D.GetLength(0); x++)

                    {

                        Console.Write(3D[x, y, i]);

                    }

                    Console.WriteLine();

                }

                Console.WriteLine();

                Console.ReadKey();

            }

        }

    }

}

Output

three_dim_array.jpg

Ask Your Question 

Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.