Mega Code Archive

 
Categories / C# Book / 03 Collections
 

0348 Array Enumeration

You can enumerate using the static Array.ForEach method: public static void ForEach<T> (T[] array, Action<T> action); This uses an Action delegate, with this signature: public delegate void Action<T> (T obj); using System; using System.Collections; class Sample { public static void Main() { Array.ForEach(new[] { 1, 2, 3 }, Console.WriteLine); } } The output: 1 2 3