示例如何在C#中创建3维数组

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();
            }

        }
    }
}
C#中的三维数组

在本文中,我将解释如何创建三维数组。

在三维数组中,我们只需要一个索引来访问数组成员。
这些类型的数组用于存储预定义类型的项目数。
多维数组是一系列数组,以便每个数组包含自己的子数组。

日期:2020-04-11 23:03:53 来源:oir作者:oir