如何在c#中将int值集合添加到List中

时间:2015-09-15 06:44:49

标签: c# arraylist generic-list

我创建了这个arraylist:

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

现在我想要的是,在按钮按下时,会添加一个3 * 1的int数组,这就是我得到的:

arrayList_objects.Add(int[](0,1,2))

现在它给了我一个语法错误。 谢谢你的努力。

1 个答案:

答案 0 :(得分:0)

只需创建一个这样的数组列表:

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

或者像这样:

List<int[]> arrayList = new List<int[]>
{
    new int[] { 1, 2, 3, 4 },
    new int[] { 5, 6, 7 }
};

然后用这个做任何你想做的事:)