2 DArrays
2 DArrays
In order to create a 2D array, inside the square brackets, add a comma and put each
array within its own segment of curly brackets:
Eggs is now an array with 2 arrays as its elements, each of which hold three
elements. You can think of the two arrays as seperate rows and the elements in each
as columns:
In order to access a 2D array, you needto specify two indexes, one of which (the
first) being for the array and the other being for the elements in the array. You
can also think of the first index as the row and the second as a column (make sure
not to mix this up with (x, y) in maths as you go down rows then across columns):
A foreach loop will loop through each elements in each array in order:
You can also use a regular for loop but you need the GetLength() method instead of
simply the .Length method: