C# 如何创建一个 int 数组列表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13886115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create an List of int arrays?
提问by TreeNode
I want to create a list and each element of it is an array, similarly to an array of structs in C language. Can it be done in c# and how if it can? Thanks very much!
我想创建一个列表,其中的每个元素都是一个数组,类似于 C 语言中的结构数组。可以在 c# 中完成吗?如果可以的话怎么办?非常感谢!
Wrong:
List<int[]> arrayList = new List<int[]>;
错误的:
List<int[]> arrayList = new List<int[]>;
采纳答案by Robert Davis
You're missing parenthesis at the end of your new clause.
您在新条款的末尾缺少括号。
List<int[]> arrayList = new List<int[]>();
List<int[]> arrayList = new List<int[]>();
回答by Marcus Davies
List<Int[]> arrList = new List<Int[]>();
int[] ArrayOfInts = new int[10];
fill as required
按要求填写
arrList.Add(ArrayOfInts);
回答by JG in SD
If you know your starting values you can also initialize it like so:
如果你知道你的起始值,你也可以像这样初始化它:
List<int[]> arrayList = new List<int[]>
{
new int[] { 1, 2, 3, 4 },
new int[] { val1, val2, val3 },
otherIntArray
};

