有一个类,如Student,有学号、数学成绩、语文成绩,
存在List列表中,要将List按数学成绩排序,怎么办呢?
List<Student> scores=GetScores();
scores.Sort( (l,r)=>l.MathScore.CompareTo(r.MathScore) );//数学成绩升序
scores.Sort( (l,r)=>r.MathScore.CompareTo(l.MathScore) );//数学成绩降序
Sort中的是一个lambda表达式
转载于:https://www.cnblogs.com/sinceret/p/10707475.html
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
QQ咨询|关于我们|Archiver|手机版|小黑屋|( 辽ICP备15012455号-4 ) Powered by 期权论坛 X3.2 © 2001-2016 期权工具网&期权论坛 Inc.
下载期权论坛手机APP