What is the difference between a jagged array and a multidimensional array?

C# Collections Basic Fresher1–2 Yrs Conceptual 1 min read

Quick Answer

A multidimensional array (int[,]) is a single rectangular block — every row has the same length. A jagged array (int[][]) is an array of arrays — each inner array can be a different length (or null). Jagged is usually faster in .NET because the JIT optimises single-dimension array access better.

A multidimensional array like int[3,4] is one solid rectangular block where every row is the same width. A jagged array, int[][], is really an array whose elements are themselves arrays, so each row can be a different length or even null. Jagged tends to be faster in .NET because the runtime optimises plain single-dimension array indexing really well, whereas multidimensional access goes through slower helper methods. So I use multidimensional for an actual fixed matrix and jagged for anything ragged or performance-sensitive.

  • int[,] grid = new int[3, 4]; — one allocation, contiguous, bounds-checked as one unit.
  • int[][] rows = new int[3][]; rows[0] = new int[4]; — one outer + N inner allocations.
  • Use multidimensional for a true fixed grid/matrix; jagged for ragged data or when performance matters.