Executing a certain action for all elements in an Enumerable<T>

c#-3.0, enumerable, linq

Solution

A quick-and-easy way to get this is:

Names.ToList().ForEach(e => ...);

Problem

I have an `Enumerable<T>` and am looking for a method that allows me to execute an action for each element, kind of like `Select` but then for side-effects. Something like: ``` string[] Names = ...; Names.each(s => Console.Writeline(s)); ``` or ``` Names.each(s => GenHTMLOutput(s)); // (where GenHTMLOutput cannot for some reason receive the enumerable itself as a parameter) ``` I did try `Select(s=> { Console.WriteLine(s); return s; })`, but it wasn't printing anything.

Original source

Related problems