OrderBy在Lambdaexpression式中下降?

我知道在正常的Linq语法中,由orderby xxx descending是很容易的,但是我如何在Lambdaexpression式中做到这一点?

正如Brannon所说,它是OrderByDescendingThenByDescending

 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); 

使用System.Linq.Enumerable.OrderByDescending()

例如:

 var items = someEnumerable.OrderByDescending(); 

尝试这个:

 List<int> list = new List<int>(); list.Add(1); list.Add(5); list.Add(4); list.Add(3); list.Add(2); foreach (var item in list.OrderByDescending(x => x)) { Console.WriteLine(item); } 

试试这个方法,

 var qry = Employees .OrderByDescending (s => s.EmpFName) .ThenBy (s => s.Address) .Select (s => s.EmpCode); 

Queryable.ThenBy

LastOrDefault()通常不工作,但与Tolist()它将工作。 不需要使用OrderByDescending像这样使用Tolis()

 GroupBy(p => p.Nws_ID).ToList().LastOrDefault();