Do all for IEnumerable and Action
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public static class IEnumerableExtension
{
public static void DoAll<T>(this IEnumerable<T> collection, Action<T> action)
{
for (int index = 0; index < collection.Count(); index++)
{
T item = collection.ElementAt<T>(index);
action(item);
}
}
public static void TryDoAll<T>(this IEnumerable<T> collection, Action<T> action)
{
DoAll<T>(collection, param =>
{
try
{
action(param);
}
catch (System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
});
}
}
Related examples in the same category