如何创建一个3D数组? [英] How to create a 3d array?
本文介绍了如何创建一个3D数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在以下数组中添加更多边界?
How do I add more bounds the following array?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleOne
{
class Program
{
static void Main(string[] args)
{
//Create a 4x2 array (a grid with four rows and two columns).
int[,] intArray = { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };
int rows = intArray.GetUpperBound(0); // rows = 4
int columns = intArray.GetUpperBound(1); // columns = 2
int third = intArray.GetUpperBound(2); //3rd dimension
Console.WriteLine("rows= " + rows + " columns= " + columns);
Console.WriteLine("third= " + third);
Console.ReadKey(true);
}
}
}
显示如何创建2d数组的多维数组此处.
Multidimensional arrays showing how to create 2d arrays here.
推荐答案
class Sample
{
public static void Main(string[] args)
{
int[,,] intArray =
{
{
{1,2,3}, {4,5,6}, {7,8,9}
},
{
{10,11,12}, {13,14,15}, {16,17,18}
}
};
}
}
等等...
..and so on...
using System;
public class CSharpApp
{
static void Main()
{
int[,,] n3 = {
{{12, 2, 8}},
{{14, 5, 2}},
{{3, 26, 9}},
{{4, 11, 2}}
};
int d1 = n3.GetLength(0);
int d2 = n3.GetLength(1);
int d3 = n3.GetLength(2);
for (int i=0; i<d1;>
{
for (int j=0; j<d2;>
{
for (int k=0; k<d3;>
{
Console.Write(n3[i, j, k] + " ");
}
}
}
Console.Write('\n');
}
}
链接足以理解3D阵列,这里是:多维阵列 [
Hi,
A link is sufficient to understand 3D Array, and here it is : Multidimentional Array[^]
Thanks
-Amit Gajjar
这篇关于如何创建一个3D数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文