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:


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.

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

The following two tabs change content below.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">