I’m looking to do a GroupBy and a Select in Linq, but the following doesn’t compile:
foreach (string fooName in fooList.GroupBy(f => f.Name).Select(f => f.Name))
{
...
}
Why am I unable to use f => f.name in my Select clause? More importantly, is there any way around this?
GroupByreturns a sequence ofIGrouping<TKey, TSource>, so the lambda parameter in theSelectmethod is of typeIGrouping<TKey, TSource>, notTSource. Instead you can do this:But anyway, there is a simpler way to achieve the same result: