Jagged With SubArrays : Jagged Arrays : Data Structure C# Examples


C# Examples » Data Structure » Jagged Arrays »

 

Jagged With SubArrays





A jagged array is an array of arrays in which the length of each array can differ.




    
using  System;

class  MainClass
{
      static  void  Main()
      {
            int[][,]  Arr;              
            Arr  =  new  int[2][,];

            Arr[0]  =  new  int[,]  {  {  1,  2  },  {  10,  20  }  };
            Arr[1]  =  new  int[,]  {  {  3,  4,  5  },  {  30,  40,  50  }  };

            for  (int  i  =  0;  i  <  Arr.GetLength(0);  i++)
            {
                  for  (int  j  =  0;  j  <  Arr[i].GetLength(0);  j++)
                  {
                        for  (int  k  =  0;  k  <  Arr[i].GetLength(1);  k++)
                        {
                              Console.WriteLine  ("[{0}][{1},{2}]  =  {3}",  i,  j,  k,  Arr[i][j,  k]);
                        }
                  }
            }
      }
}
    
   
  
   



Output

[0][0,0] = 1
[0][0,1] = 2
[0][1,0] = 10
[0][1,1] = 20
[1][0,0] = 3
[1][0,1] = 4
[1][0,2] = 5
[1][1,0] = 30
[1][1,1] = 40
[1][1,2] = 50


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» Jagged Arrays