Jagged Arrays in C#
By ruzaib khan
A special type of array is introduced in C#. A Jagged Array is an array of an array in which the length of each array index can differ.
A Jagged Array can be used is to create a table in which the lengths of the rows
are not same. This Array is declared using square brackets ( [ ] ) to indicate
each dimension.
The following code demonstrates the creation of a two-dimensional jagged array.
class Jagged
{
public static void Main()
{
int [][] jagged=new int [3][];
jagged[0]=mew int[4]
jagged[1]=mew int[3]
jagged[2]=mew int[5]
int I;
//Storing values in first array
for (I=0;I<4;I++)
jagged[0][I]=I;
//Storing values in second array
for( I=0;I<3;I++)
jagged[1][I]=I;
//Storing values in third array
for(I=0;I<5;I++)
jagged[2][I]=I;
//Displaying values from first array
for (I=0;I<4;I++)
Console.WriteLine(jagged[0][I])
//Displaying values from second array
for (I=0;I<3;I++)
Console.WriteLine(jagged[1][I])
//Displaying values from third array
for(I=0;I<5;I++)
Console.WriteLine(jagged[2][I])
}
}
Jagged Arrays in C# (637 Views)