C# – Jagged Arrays

C# provides the ability to create a special type of two dimensional array called as Jagged Array. In simple terms, a jagged array is an array of arrays. A jagged array is a little different than a two dimensional array, the major difference being that in a jagged array the length of each array may differ. Thus, a jagged array can be used to create a table in which the lengths of the rows are not the same.

Declaring a jagged array:

Example:

After the jagged array has been declared, we have to initialize individual array of the jagged array.
Initializing the jagged array:

and so on..
You can also use a for loop to initialize the jagged array.

Assigning values to the jagged array:
Once we have initialized the jagged array, we can now store values in the jagged array. Values can be stored by using the two indexes along with the jagged array name.
Example:

Just like in declaration, you could also use a for loop to store values in a jagged array.
Example:

The following two tabs change content below.