How to create an List of int arrays?
95,189
Solution 1
You're missing parenthesis at the end of your new clause.
List<int[]> arrayList = new List<int[]>();
Solution 2
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
};
Solution 3
List<Int[]> arrList = new List<Int[]>();
int[] ArrayOfInts = new int[10];
fill as required
arrList.Add(ArrayOfInts);
Author by
TreeNode
Updated on December 15, 2020Comments
-
TreeNode over 3 years
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!
Wrong:
List<int[]> arrayList = new List<int[]>;