Welcome to the utilities wiki! This is a work in progress. Feel free to contribute.
List<T> implements ForEach(), which is a lot of fun. But we need other places to use it. Here you go:
List<T>
ForEach()
public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action) { foreach (T obj in collection) action(obj); }
Now if you refactor your code that uses List<T> to use IEnumerable<T>, you don't have to rewrite all your loops. For example:
IEnumerable<T>
var list = GetList(); list.ForEach(i => i.Counter++);
This will still work:
var list = GetList().AsEnumerable(); list.ForEach(i => i.Counter++);
There was an error while loading. Please reload this page.