# 数组Arrays

using System;
class ArrayExample
{
static void Main()
{
int[] a = new int[10];
for (int i = 0; i < a.Length; i++)
{
a[i] = i * i;
}
for (int i = 0; i < a.Length; i++)
{
Console.WriteLine(\$"a[{i}] = {a[i]}");
}
}
}

int[] a1 = new int[10];
int[,] a2 = new int[10, 5];
int[,,] a3 = new int[10, 5, 2];

a1 数组包含 10 个元素，a2 数组包含 50 个元素 (10 × 5)，a3 数组包含 100 个元素 (10 × 5 × 2)。The a1 array contains 10 elements, the a2 array contains 50 (10 × 5) elements, and the a3 array contains 100 (10 × 5 × 2) elements. 数组的元素类型可以是任意类型（包括数组类型）。The element type of an array can be any type, including an array type. 包含数组类型元素的数组有时称为交错数组，因为元素数组的长度不必全都一样。An array with elements of an array type is sometimes called a jagged array because the lengths of the element arrays do not all have to be the same. 以下示例分配由 int 数组构成的数组：The following example allocates an array of arrays of int:

int[][] a = new int[3][];
a[0] = new int[10];
a[1] = new int[5];
a[2] = new int[20];

int[] a = new int[] {1, 2, 3};

int[] a = {1, 2, 3};

int[] t = new int[3];
t[0] = 1;
t[1] = 2;
t[2] = 3;
int[] a = t;