int[][] myArray = new int[10][];
foreach (int[] eachArray in myArray) {
eachArray = new int[2]
}
I believe it should create an array that is
{ 0 , 0 }
{0 , 0}
.........
Jagged array is so confusing.....
This will not create the jagged array you are looking for. It's attempting to assign a new int[2] instance to the iteration variable, not to the slot in the original array. This won't even compile as the iteration variable is treated as readonly by the compiler
The way to do this is with a for loop
for (var i = 0; i < myArray.Length; i++) {
myArray[i] = new int[2];
}
for loop is the standard way of doing it. It can be done with a full blown initializer but that requires initializing the entire array inline.
List<List<int>>instead. It has also the advantage that it's resizable without overhead(copying into another array).