0Pricing
C# Academy · Lesson

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]); // 0

All lessons in this course

  1. Declaring Arrays
  2. Indexing and Length
  3. Looping Over Arrays
  4. Multidimensional Arrays
← Back to C# Academy