C# 有多维数组,但也有数组数组(也称为锯齿数组)。第二种形式是您所追求的:
// This is a jagged array. It has 3 rows, each of which is an int[] in its own right.
// Each row can also have a different number of elements from all the others, so if
// a[i][N] is valid for some i and N, a[x][N] is not necessarily valid for other x != i
var a = new int[3][];
// To populate the array you need to explicitly create an instance for each sub-array
for (int i = 0; i < 3; i++)
{
a[i] = new[] { i, i + 3 };
}
// And now this is possible:
var b = a[2];
如果您手头有一个多维数组,则需要手动进行复制。