I have two IEnumerable IGrouping in my C# program:
IEnumerable<IGrouping<string, FileItem>> number1
IEnumerable<IGrouping<string, FileItem>> number2
Is it somehow possible to concat these two IEnumerable into one?
I have two IEnumerable IGrouping in my C# program:
IEnumerable<IGrouping<string, FileItem>> number1
IEnumerable<IGrouping<string, FileItem>> number2
Is it somehow possible to concat these two IEnumerable into one?
Concat
should work:
IEnumerable<IGrouping<string, FileItem>> concatenated = number1.Concat(number2);
https://msdn.microsoft.com/en-us/library/bb302894(v=vs.110).aspx
This doesn't merge groups, but only concat the enumeration, with keys duplicated. The following code illustrate the issue:
var mergedGroups = firstGroups .Concat ( secondGroups );
var duplicateKeys = mergedGroups .GroupBy(group => group.Key) .Where(group => group.Count() > 1) .Select(group => group.Key) .ToList();
You could make use of the
Concat
method:For more info about this method, please have a look here.