(I assume this is for LINQ for objects. Everything else will be implemented differently :)
It simply returns everything from the first, and then everything from the second. All data is streamed. Something like that:
public static IEnumerable<T> Concat(this IEnumerable<T> source1,
IEnumerable<T> source2)
{
if (source1 == null)
{
throw new ArgumentNullException("source1");
}
if (source2 == null)
{
throw new ArgumentNullException("source1");
}
return ConcatImpl(source1, source2);
}
private static IEnumerable<T> ConcatImpl(this IEnumerable<T> source1,
IEnumerable<T> source2)
{
foreach (T item in source1)
{
yield return item;
}
foreach (T item in source2)
{
yield return item;
}
}
I divided this into two methods to verify the argument is correct, but I can still use an iterator block. (No code inside the iterator block is executed until the first call of the MoveNext()result).
source
share