Example of foreach statement used with a rectangular array in C#

class Program 
{ 
  static void Main() 
  { 
	 int total = 0; 
	 int[,] arr1 = { {10, 11}, {12, 13} }; 
 
	 foreach( var element in arr1 ) 
	 { 
		total += element; 
		Console.WriteLine("Element: {0}, Current Total: {1}" , element, total); 
	 } 
  } 
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.