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++)

       //Storing values in second array
      for( I=0;I<3;I++)

      //Storing values in third array

      //Displaying values from first array
      for (I=0;I<4;I++)

      //Displaying values from second array
      for (I=0;I<3;I++)

      //Displaying values from third array

Jagged Arrays in C#  (637 Views)