Hello,
I am trying to Group elements on the remainder of an integer when they are divided by 5.
nt[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
Such that, for instance, numbers with a remainder of 0 when divided by 5 are -- > 5 and 0 (0, new [] {5, 0})
However, I am receiving the following error:
I understand that it expects the
Enumerable
return type instead of
IGrouping
, but I cannot figure out how to fix it. Any help would be appreciated. Thank you.
Error CS0266 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<<anonymous type: int Key, System.Linq.IGrouping<int, int> g>>'
to
'System.Collections.Generic.IEnumerable<(int remainder, System.Collections.Generic.IEnumerable<int> numbers)>'
What I have tried:
public static IEnumerable<(int remainder, IEnumerable<int> numbers)> Grouping()
{
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var numberGroups = from n in numbers
group n by n % 5 into g
select new { g.Key, g };
return numberGroups;
}