OrderBy descending in Lambda expression?
在正规文法的LINQ技术,很容易
正如布兰农所说,它是
1 2 3 | var query = from person in people orderby person.Name descending, person.Age descending select person.Name; |
相当于:
1 2 3 | var query = people.OrderByDescending(person => person.Name) .ThenByDescending(person => person.Age) .Select(person => person.Name); |
使用
例如:
1 | var items = someEnumerable.OrderByDescending(); |
试试这个:
1 2 3 4 5 6 7 8 9 10 11 | 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); } |
尝试另一种方法:
1 2 3 4 | var qry = Employees .OrderByDescending (s => s.EmpFName) .ThenBy (s => s.Address) .Select (s => s.EmpCode); |
可查询。Thenby
这只适用于有数字字段的情况,但可以在字段名称前面放一个减号,如下所示:
1 | reportingNameGroups = reportingNameGroups.OrderBy(x=> - x.GroupNodeId); |
但是,当您在
在
1 | GroupBy(p => p.Nws_ID).ToList().LastOrDefault(); |