I have two instances of
IEnumerable<T> (with the same
T). I want a new instance of
IEnumerable<T> which is the concatenation of both.
Is there a built-in method in .NET to do that or do I have to write it myself?
Yes, LINQ to Objects supports this with
var together = first.Concat(second);
second be null you would receive a
ArgumentNullException. To avoid this & treat nulls as you would an empty set, use the null coalescing operator like so:
var together = (first ?? Enumerable.Empty<string>()).Concat(second ?? Enumerable.Empty<string>()); //amending `<string>` to the appropriate type