I know this question has been asked many times before but I tried out the answers and they don\'t seem to work.
I have two lists of the same length but not the same
You can wrap the two IEnumerable<> in helper class:
var nums = new []{1, 2, 3};
var strings = new []{"a", "b", "c"};
ForEach(nums, strings).Do((n, s) =>
{
Console.WriteLine(n + " " + s);
});
//-----------------------------
public static TwoForEach ForEach(IEnumerable a, IEnumerable b)
{
return new TwoForEach(a, b);
}
public class TwoForEach
{
private IEnumerator a;
private IEnumerator b;
public TwoForEach(IEnumerable a, IEnumerable b)
{
this.a = a.GetEnumerator();
this.b = b.GetEnumerator();
}
public void Do(Action action)
{
while (a.MoveNext() && b.MoveNext())
{
action.Invoke(a.Current, b.Current);
}
}
}