我如何对班级中的项目进行排序? [英] How do I sort items in my class?
问题描述
我班上有学生(我当然是c#班),每个学生都有自己的考试分数值。
我创建了List并添加了学生+积分那里。我把我的名单写成了最好的学生。
但现在,我想对我的学生进行排序:
1.降序可靠点
- 马克 - 50分
- 大卫 - 40 p
- 罗纳德 - 10 p(仅举例)
2. alphabeticaly
这些线条会是什么样子?
我尝试了什么:
我尝试过类似:var result = students.OrderByDescending(??? => ???)。ToList();
或类似:Student.Max(); - 这看起来不错,但C#不明白,我想用什么作为我的订单模式..当然:(
试试:
var result = students.OrderByDescending(s = > s.Mark);
并且:
var result = students.OrderByDescending(s = > s.Name);
< blockquote>试试这个
var result = students.OrderByDescending(k = > k.points).ThenBy(k = > k.Name)。ToList() ;
I´ve got students in my class(I mean c# class of course), each student has got his own point value from exam.
I created List and added Students + points there. I made my List to write best Student.
But now, I want to sort my students:
1. Descending dependable on points
- Mark - 50 points
- David - 40 p
- Ronald - 10 p (just example)
2. alphabeticaly
how would these lines look like?
What I have tried:
I´ve tried something like: var result = students.OrderByDescending(??? => ???).ToList();
or like: Student.Max(); -- this looks great but C# doesn´t understand, what do I want to use as my order pattern.. of course :(
Try:
var result = students.OrderByDescending(s => s.Mark);
And:
var result = students.OrderByDescending(s => s.Name);
try this
var result = students.OrderByDescending(k => k.points).ThenBy(k => k.Name).ToList();
这篇关于我如何对班级中的项目进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!