Hi all,

I were heavily exercising LINQ in one of my Lexical Analyzer application, in course somewhere i felt that given a Enumerable collection and a action delegate, there is no extensions in Linq to perform an action on each element in the collection. I don’t actually know if there exists one like this, but i ain’t happen to find such. May be the giants think that there is not much of a value in saving a programmer from writing a for each loop and executing an action. So i wrote something as follows, which holds good for all IEnumerable<T> objects.

using System;
using System.Linq;
using System.Collections.Generic;

namespace IMissInLinq
{
class Program
{
static void Main(string[] args)
{
IEnumerable<int> myData = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
myData.Do(new Action<int>(data => Console.WriteLine(data)));
}
}

public static class Extensions
{
public static void Do<T>(this IEnumerable<T> collection, Action<T> WhatToDo)
{
foreach (T item in collection)
{
WhatToDo(item);
}
}
}
}