I have two sets of datarows. They are each IEnumerable. I want to append/concatenate these two lists into one list. I\'m sure this is doable. I don\'t want to do a for loop
Delayed invocation of the second and subsequent enumerables
I usually use Linq IEnumerable but today I needed to be 100% sure that the second enumeration was not enumerated until the first one has been processed until the end. (e.g. two db queries that I didn't want to run simultaneously). So the following function made the trick to delay the enumerations.
IEnumerable DelayedConcat(params Func>[] enumerableList)
{
foreach(var enumerable in enumerableList)
{
foreach (var item in enumerable())
{
yield return item;
}
}
}
Usage:
return DelayedConcat(
() => GetEnumerable1(),
() => GetEnumerable2(),
// and so on.. () => GetEnumerable3(),
);
In this example GetEnumerable2 function invocation will be delayed until GetEnumerable1 has been enumerated till the end.