What are the differences between a multi-dimensional array and jagged array?

CsharpProgrammingServer Side Programming

Multi-dimensional array

Multi-dimensional arrays are also called rectangular array. You can define a 3-dimensional array of integer as −

int [ , , ] val;

Let us see how to define a two-dimensional array.

int[,] val = new[3,3]

Jagged array

A Jagged array is an array of arrays. To access an element from it, just mention the index for that particular array.

Here, we have a jagged array with 5 array of integers −

int[][] a = new int[][]{new int[]{0,0},new int[]{1,2}, new int[]{2,4},new int[]{ 3, 6 }};
Published on 14-Aug-2018 11:45:46