Alex Rivera | Logout

Differences between a multidimensional array "[,]" and an array of arrays "[][]" in C#?

Asked 2009-02-28T07:55:41.767
526

What are the differences between multidimensional arrays double[,] and array of arrays double[][] in C#?

If there is a difference?
What is the best use for each one?

Edit
Report

1 Answer

15

Multi-dimension arrays are (n-1)-dimension matrices.

So int[,] square = new int[2,2] is square matrix 2x2, int[,,] cube = new int [3,3,3] is a cube - square matrix 3x3. Proportionality is not required.

Jagged arrays are just array of arrays - an array where each cell contains an array.

So multi-dimensional arrays are proportional, and jagged arrays may be not be. Each cell can contain an array of arbitrary length.

answered 2009-02-28T20:23:18.223

Your Answer