如何创建int数组列表?

时间:2012-12-14 20:55:17

标签: c# .net syntax

我想创建一个列表,它的每个元素都是一个数组,类似于C语言中的结构数组。 它可以在c#中完成,如果可以的话? 非常感谢!

错: List<int[]> arrayList = new List<int[]>;

3 个答案:

答案 0 :(得分:41)

您在新条款末尾缺少括号。

List<int[]> arrayList = new List<int[]>();

答案 1 :(得分:7)

如果你知道你的起始值,你也可以这样初始化它:

List<int[]> arrayList = new List<int[]>
{
    new int[] { 1, 2, 3, 4 },
    new int[] { val1, val2, val3 },
    otherIntArray
};

答案 2 :(得分:5)

List<Int[]> arrList = new List<Int[]>();
int[] ArrayOfInts = new int[10];

按要求填写

arrList.Add(ArrayOfInts);