The difference is that [,] is a 2D fixed size array containing exactly x * y elements, where x and y are given when you allocate the space in the
new
assignment:
int[,] arr = new int[x,y];
[][] creates a jagged array, where you only assign one dimension at a time:
int[][] arr = new int[x][];
for(int i = 0; i < x; i++)
{
arr[i] = new int[(i + 1) * 2];
}
Each element of the jagged array can be a different size, and needs to be allocated with a separate
new
statement.
While you can initialize fixed size arrays with this syntax:
int[,] arr = new int[5, 2] { { 0, 0 }, { 1, 2 }, { 2, 4 }, { 3, 6 }, { 4, 8 } };
You need this syntax to do the same with a jagged array:
int[][] arr = new int[5][] { new int[] { 0, 0 },
new int[] { 1, 2 },
new int[] { 2, 4 },
new int[] { 3, 6 },
new int[] { 4, 8 } };