A particular kind of array is introduced in C#. A Jagged Array is an array of an array in which the distance of both array indexes can be deferent.
Example: A Jagged Array can be used is to make a table in which the lengths of the rows are deferent. This Array is stated with square brackets 甜 ] 鍍o specify each aspect. The subsequent code demonstrates the creation of a two-dimensional jagged array
Code:
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;
全toring values in first array
For (I=0; I<4; I++)
Jagged [0][I]=I;
全toring values in second array
for( I=0;I<3;I++)
jagged[1][I]=I;
全toring values in third array
for(I=0;I<5;I++)
jagged[2][I]=I;
船isplaying values from first array
for (I=0;I<4;I++)
Console.WriteLine(jagged[0][I])
船isplaying values from second array
for (I=0;I<3;I++) Console. Write Line (jagged[1][I]) 船isplaying values from third array
for(I=0;I<5;I++)
Console. Write Line (jagged[2][I])
}
}
Bookmarks