Click here to Skip to main content
15,908,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

in C# one can declare a two-dimensional array of integral numbers in different ways:
int[,] a;
int[][] b;
What is the difference between the two?
In what cases am I to prefer one over the other?

Thanks in advance,


luker
Posted

1 solution

Hi,

The first one,
int[,] a;
is called Rectangular array. It is the common way for declaring two-dimentional array or multi-dimentional array.

The second one,
int[][] b; 
is called Jagged array. To explain simply, Jagged array is array of array.

Here number of rows is fixed but we can changed the number of columns.

For example, 1st row can contain 5 columns (say...), 2nd row can be changed to have 7 columns (say...)... This is the purpose of Jagged array.

Regards,
Suresh
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900