I have a ForEachWithIndex EM
static void ForEachWithIndex<T>(this IEnumerable<T> enu, Action<T, int> action)
{
int i = 0;
foreach(T item in enu)
action(item, i++);
}
I call it like this
my_int_array.ForEachWithIndex((x, i) => x += i);
Now i want to create one which checks for condition and then perform that action.
Usually i use above as
my_int_array.ForEachWithIndex((x,i) =>
{
if (x != 0)
x += i;
});
I want a EM that takes that condition as parameter also. How to do that?
You need to pass an additional Func parameter, something like this:
And this is what the code for your example look like: