重构 LINQ 以查询表达式
本文关键字:查询表 表达式 查询 LINQ 重构 | 更新日期: 2023-09-27 17:56:39
如何将此 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;
}