/ Published in: C#
Expand |
Embed | Plain Text
using System; using System.Collections.Generic; namespace ForEachExample { public static class Utility { public static void ForEach<T>(this IEnumerable<T> coll, Action<T> function) { IEnumerator<T> en = coll.GetEnumerator(); while (en.MoveNext()) function(en.Current); } } class Program { static void Main(string[] args) { //Expexted output: 123 array.ForEach(val => Console.Write(val)); } } }
You need to login to post a comment.
