C# List集合根据对象某个字段排序

public class Student
{
    public string name;
    public int num;
}

List<Student>  students=new List<Student>();
//假设students集合里面添加了数据
List<Student> temp1= students.OrderBy(s => s.num).ToList();//num 小大到
List<Student> temp2= students.OrderByDescending(s => s.num).ToList();//num 大到小
//转载请保留 http://www.luofenming.com/show.aspx?id=ART2021042500001

评论