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[]>;
3 Answers
You're missing parenthesis at the end of your new clause.
List<int[]> arrayList = new List<int[]>();
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 }; List<Int[]> arrList = new List<Int[]>(); int[] ArrayOfInts = new int[10]; fill as required
arrList.Add(ArrayOfInts);