Subarrays in Jagged Arrays in C#

int[][,] Arr;         // An array of 2-D arrays 
Arr = new int[3] [, ];  // Instantiate an array of three 2-D arrays. 
 
Arr[0] = new int[, ] { { 10, 20 },         { 100, 200 }           }; 
Arr[1] = new int[, ] { { 30, 40, 50 },     { 300, 400, 500 }      }; 
Arr[2] = new int[, ] { { 60, 70, 80, 90 }, { 600, 700, 800, 900 } }; 
 
//Get length of dimension 0 of Arr 
for (int i = 0; i < Arr. GetLength(0) ; i++) 
{ //Get length of dimension 0 of Arr[i] 
  for (int j = 0; j < Arr[i]. GetLength(0) ; j++) 
  {  
     //Get length of dimension 1 of Arr[i ] 
	 for (int k = 0; k < Arr[i] .GetLength(1); k++) { 
		 Console. WriteLine 
				 (" [{0}][{1}, {2}] = {3}", i, j, k, Arr[i] [j, k] ); 
	 } 
	 Console. WriteLine(""); 
  } 
  Console.WriteLine("") ; 
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.