Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between using int[][] and int[,]? [duplicate]

Coming from a perl background, I have always defined a 2D array using int[][]. I know you can use int[,] instead so what are the differences?

like image 981
Callum Rogers Avatar asked Jul 21 '09 13:07

Callum Rogers


1 Answers

The difference here is that the first sample, int[][] creates a jagged array, while the second creates a rectangular array (of dimension 2). In a jagged array each "column" can be of a different size. In a true multidimensional array, each "column" (in a dimension) is the same size. For more complete information see the Array section of the C# Programming Guide.

like image 99
tvanfosson Avatar answered Sep 28 '22 02:09

tvanfosson