Multidimensional Arrays
Grids and jagged arrays.
Beyond a Single Row
So far arrays were a single line of values. A multidimensional array stores values in a grid, like a spreadsheet with rows and columns.
These are great for game boards, tables, and matrices.
Declaring a 2D Array
A two-dimensional array uses a comma inside the brackets: [,]. You give two sizes, the number of rows and the number of columns.
This grid has 2 rows and 3 columns, so it holds 6 values.
int[,] grid = new int[2, 3];
Console.WriteLine(grid[0, 0]); // 0All lessons in this course
- Declaring Arrays
- Indexing and Length
- Looping Over Arrays
- Multidimensional Arrays