this question has answer here:
- c# list<> sort x y 6 answers
i have list of items want sort can't seems lambda expression right. can leads me lambda expression? thanks
unsorted list item:
number: 2, date: 21/10/2010 11:22:55 number: 1, date: 21/10/2010 11:22:55 number: 2, date: 20/10/2010 12:10:00 number: 1, date: 20/10/2010 12:10:00
sorted list item:
number: 1, date: 21/10/2010 11:22:55 number: 1, date: 20/10/2010 12:10:00 number: 2, date: 21/10/2010 11:22:55 number: 2, date: 20/10/2010 12:10:00 itemlist.sort((x, y) => ...);
you can use linq's orderby
, thenbydescending
extension methods:
using system.linq; ... var sorteditems = itemlist.orderby(x => x.number) .thenbydescending(x => x.date);
this create new object. if want assign original itemlist
, this:
using system.linq; ... itemlist = itemlist.orderby(x => x.number) .thenbydescending(x => x.date) .tolist();
Comments
Post a Comment