Jagged Array using for each Loop

  1. using System;.  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. namespace ram   
  6. {  
  7.     class Program   
  8.     {  
  9.         static void Main(string[] args)   
  10.         {  
  11.             int[][] A = new int[3][];  
  12.             A[0] = new int[5] {  
  13.                 23,  
  14.                 34,  
  15.                 43,  
  16.                 12,  
  17.                 89  
  18.             };  
  19.             A[1] = new int[4] {  
  20.                 87,  
  21.                 76,  
  22.                 90,  
  23.                 98  
  24.             };  
  25.             A[2] = new int[6] {  
  26.                 34,  
  27.                 5,  
  28.                 6,  
  29.                 8,  
  30.                 76,  
  31.                 98  
  32.             };  
  33.             Console.WriteLine("elements of jagged array are :-");  
  34.             foreach(int[] i in A) {  
  35.                 foreach(int j in i) {  
  36.                     Console.Write(j + " ");  
  37.                 }  
  38.                 Console.WriteLine();  
  39.             }  
  40.             Console.Read();  
  41.         }  
  42.     }  
  43. }