有一个类,如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表达式

相关文章:

  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2021-11-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
  • 2022-01-29
  • 2022-12-23
相关资源
相似解决方案