多維數組:
using System;
class MyClass
{
static void Main()
{
int[,,] arr = new int[2, 3, 4];
for (int x = 0; x < 2; x++) for (int y = 0; y < 3; y++) for (int z = 0; z < 4; z++)
arr[x,y,z] = Convert.ToInt32(Convert.ToString(x+1) + Convert.ToString(y+1) + Convert.ToString(z+1));
foreach (int i in arr) Console.WriteLine(i);
Console.ReadKey();
}
}
數組中的數組:
using System;
class MyClass
{
static void Main()
{
int[][] arr = new int[3][];
arr[0] = new int[2] { 11, 12 };
arr[1] = new int[3] { 21, 22, 23 };
arr[2] = new int[4] { 31, 32, 33, 34 };
foreach (int[] ns in arr) foreach (int n in ns)
Console.WriteLine(n);
Console.ReadKey();
}
}