I have an Enumerable
and am looking for a method that allows me to execute an action for each element, kind of like Select
but then for si
There is a ForEach method off of List. You could convert the Enumerable to List by calling the .ToList() method, and then call the ForEach method off of that.
Alternatively, I've heard of people defining their own ForEach method off of IEnumerable. This can be accomplished by essentially calling the ForEach method, but instead wrapping it in an extension method:
public static class IEnumerableExtensions
{
public static IEnumerable ForEach(this IEnumerable _this, Action del)
{
List list = _this.ToList();
list.ForEach(del);
return list;
}
}