重构 LINQ 以查询表达式



如何将此 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;
}

相关内容

  • 没有找到相关文章

最新更新