LINQ使用小贴士
LINQ中的排序操作符
OrderBy:按升序对序列的元素进行排序。
OrderByDescending:按降序对序列的元素排序。
ThenBy:按升序对序列中的元素执行后续排序。
ThenByDescending:按降序对序列中的元素执行后续排序。
Reverse:反转序列中元素的顺序。
示例:将员工列表进行排序,排序要求:
1、按部门编号升序;
2、按员工薪资降序;
3、按员工入职时间升序;
empList = empList.OrderBy(a => a.DeptID).ThenByDescending(a => a.Salary).ThenBy(a => a.EntryTime).ToList();