如何将此 LINQ 重构为查询表达式?
private static IEnumerable GetNameOccurrence(IEnumerable<string> allNames)
{
var nameTest = allNames.GroupBy(n => n).
Select(group =>
new
{
Name = group.Key,
Count = group.Count()
}).OrderByDescending(group => group.Count);
return nameTest;
}
这是你要找的吗?
private static IEnumerable GetNameOccurrence(IEnumerable<string> allNames)
{
var nameTest =
(from name in allNames
group name by name.n into nameGroup
select new { Name = nameGroup.Key, Count = nameGroup.Count() })
.OrderByDescending(nameGroup => nameGroup.Count);
return nameTest;
}