All about Arrays in C#—Example with a Rectangular Array
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
Example with a Rectangular Array
The following example shows the foreach statement used with a rectangular array:
class Sample { static void Main() { int nTotal = 0; int[,] arr1 = { {10, 11}, {12, 13} }; foreach( int element in arr1 ) { nTotal += element; Console.WriteLine ("Element: {0}, Current Total: {1}", element, nTotal); } } }
The output is the following:
Element: 10, Current Total: 10
Element: 11, Current Total: 21
Element: 12, Current Total: 33
Element: 13, Current Total: 46
|

