Enumerate an array
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| C# Code Snippets |
| See also |
| edit |
This C# code snippet enumerates over the elements of a multidimensional array using the GetEnumerator method and the IEnumerator interface.
using System; using System.Collections; public class ArrayEnumerator { public static void Main() { string[,] strings = {{"11","12"}, {"21", "22"}, {"31", "32"}}; Console.Write ("Array elements = " ); IEnumerator enumerator = strings.GetEnumerator(); while (enumerator.MoveNext()) { Console.Write ("{0}, ", enumerator.Current); } Console.WriteLine(); } }
| Array enumeration example (program output) |
| Array elements = 11, 12, 21, 22, 31, 32, |