C#中怎么对对象数组排序
1个回答
展开全部
public class Student
{
public string Name { get; set; }
public int Age {get;set;}
}
var list = new List<Student>();
list.Add(new Student { Name = "zhangsan", Age = 13 });
list.Add(new Student { Name = "lisi", Age = 15 });
list.Add(new Student { Name = "wangwu", Age = 12 });
list.Add(new Student { Name = "qianliu", Age = 14 });
// 按照学生名称倒序排序
var list1 = (from s in list
orderby s.Name descending
select s).ToList();
// 按照把年龄大于12岁的,按照年龄,名称升序排序
var list2 = (from s in list
where s.Age > 12
orderby s.Age
orderby s.Name
select s).ToList();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询