If you have any number of possible zero collections to combine:
IEnumerable<T> Concat<T>(params IEnumerable<T>[] nullableCollections)
{
return nullableCollections.Where(nc => nc != null).SelectMany(nc => nc);
}
and later you can call:
IEnumerable<T> allElements = Concat(myElements, yourElements, theirElements);
Not worrying if any of them are zero.
source
share