如何将此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;
}
答案 0 :(得分:1)
这是你要找的吗?
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;
}