Use foreach statement to loop through jagged array : Jagged Arrays : Data Structure C# Examples


C# Examples » Data Structure » Jagged Arrays »

 

Use foreach statement to loop through jagged array









    
using  System;

class  MainClass
{
      static  void  Main()
      {
            int[][]  arr1  =  new  int[2][];
            arr1[0]  =  new  int[]  {  1,  3  };
            arr1[1]  =  new  int[]  {  1,  1,  4  };

            foreach  (int[]  array  in  arr1)            
            {
                  Console.WriteLine("Starting  new  array");
                  foreach  (int  item  in  array)          
                  {
                        Console.WriteLine("  Item:  {0}",  item);
                  }
            }
      }
}
    
   
  
   



Output

Starting new array
 Item: 1
 Item: 3
Starting new array
 Item: 1
 Item: 1
 Item: 4


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» Jagged Arrays