Each<T>

public static void Each<T>(this IEnumerable<T> items, Action<T> action)
{
    if (items == null) return;

    var cached = items;

    foreach (var item in cached)
        action(item);
}
Example:
class Item
{
    void DoSomething();
}

var items = new List<Item>();
// populate items
items.Each(item => item.DoSomething());

/* OR */

var items = new List<Item>();
// populate items
items.Each(DoSomething);

void DoSomething(Item item)
{
    // do something to item
}

Description

iterates through an IEnumerable<T> and applies an Action

Details

Double click on the code to select all.

 

;