c# list排序

List<int> tmp = new List<int>(){5,1,22,11,4};


升序:tmp.Sort((x, y) => x.CompareTo(y));

降序:tmp.Sort((x, y) => -x.CompareTo(y));

 

List<Student> students = new List<Student>();

students.Add(new Student("001","kenshincui",25));

students.Add(new Student("002", "miaoer", 23));

students.Add(new Student("003", "shenjinjuan", 22));

students.Add(new Student("004", "nieyanxin", 24));

 

升序:students .Sort((x, y) => x.Age.CompareTo(y.Age));

降序:students .Sort((x, y) => -x.Age.CompareTo(y.Age));

 

posted @ 2016-10-20 15:26  蕤颜  阅读(151)  评论(0编辑  收藏  举报