Lambda 表达式中的 OrderBy 降序排列?

2024-04-22

我知道在正常的 Linq 语法中,orderby xxx descending很简单,但是如何在 Lambda 表达式中做到这一点呢?


正如布兰农所说,这是OrderByDescending http://msdn.microsoft.com/en-us/library/system.linq.enumerable.orderbydescending.aspx and ThenByDescending http://msdn.microsoft.com/en-us/library/system.linq.enumerable.thenbydescending.aspx:

var query = from person in people
            orderby person.Name descending, person.Age descending
            select person.Name;

相当于:

var query = people.OrderByDescending(person => person.Name)
                  .ThenByDescending(person => person.Age)
                  .Select(person => person.Name);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Lambda 表达式中的 OrderBy 降序排列? 的相关文章

随机推荐