1

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?

user2672399
  • 185
  • 1
  • 10

4 Answers4

1

You could make use of the Concat method:

var concatenated = number1.Concat(number2);

For more info about this method, please have a look here.

Christos
  • 53,228
  • 8
  • 76
  • 108
0

Concat should work:

IEnumerable<IGrouping<string, FileItem>> concatenated = number1.Concat(number2);

https://msdn.microsoft.com/en-us/library/bb302894(v=vs.110).aspx

timothyclifford
  • 6,799
  • 7
  • 57
  • 85
0

Are you looking for something like that;

var groupedNumbers = number1.Concat(number2);
lucky
  • 12,734
  • 4
  • 24
  • 46
0

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();

Alexis Pautrot
  • 1,128
  • 1
  • 14
  • 18