C#中List<T>排序的两种方法

List<Student> stu = (List<Student>)Session["StudentList"];

Linq表达式:
//按学号降序
List<Student> stuList = (from s instu orderby s.stuNOdescending select s).ToList<Student>();

//按学号升序
List<Student> stuList = (from s instu orderby s.stuNO  select s).ToList<Student>();

使用Lambda表达式排序:
//按学号降序

单字段:List<Student> stuList= stu.OrderByDescending(s=> s.orderid).ToList<Student>();
多字段:List<Student> stuList= stu.OrderByDescending(s=> new{s.stuNO,s.stuName}).ToList<Student>();

//按学号升序
单字段:List<Student> stuList= stu.OrderBy(s=> s.stuNO).ToList<Student>();
多字段:List<Student> stuList= stu.OrderBy(s=> new{s.stuNO,s.stuName}).ToList<Student>();

多字段主次顺序排序情况,先按no排序,再按name排序
List<Student> stuList= stu.OrderBy(s=>
s.stuNO).ThenBy(s=>
s.stuName).ToList<Student>();

List<Student> stuList=
stu.OrderBy(s=> new{ s.stuNO }).ThenBy(s=>
new{s.stuName}).ToList<Student>();

C# 中使用Linq和Lambda表达式对List<T>进行排序的更多相关文章

  1. LInq 与lambda表达式

    LInq 与lambda表达式 LinQ是我们常用的技术之一.因为我们绕不开的要对数据进行一系列的调整,如 排序. 条件筛选.求和.分组.多表联接 等等. lambda则是我们常用的语法糖,配合lin ...

  2. 使用LINQ、Lambda 表达式 、委托快速比较两个集合,找出需要新增、修改、删除的对象

    本文需要对C#里的LINQ.Lambda 表达式 .委托有一定了解. 在工作中,经常遇到需要对比两个集合的场景,如: 页面集合数据修改,需要保存到数据库 全量同步上游数据到本系统数据库 在这些场景中, ...

  3. SQL、Linq和Lambda表达式 的关系

    首先说说这三者完全是三种不同的东西,SQL是结构化查询语言(Structured Query Language)简称,这大家再熟悉不过了,下面主要介绍LINQ和Lambda表达式的基本概念以及同一查询 ...

  4. c#封装DBHelper类 c# 图片加水印 (摘)C#生成随机数的三种方法 使用LINQ、Lambda 表达式 、委托快速比较两个集合,找出需要新增、修改、删除的对象 c# 制作正方形图片 JavaScript 事件循环及异步原理(完全指北)

    c#封装DBHelper类   public enum EffentNextType { /// <summary> /// 对其他语句无任何影响 /// </summary> ...

  5. 动态LINQ(Lambda表达式)构建

    using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; us ...

  6. Android Stutio中使用java8的Lambda表达式

    转载请标明出处: http://blog.csdn.net/xmxkf/article/details/51532028 本文出自:[openXu的博客] 目录: 为什么要使用Lambda表达式 让A ...

  7. .Net Linq与Lambda表达式中GroupBy以多个字段分组

    一.引入 基本上熟悉C#语言的没有不知道Lambda表达式的,其对于数据的处理真的是太方便了.其中分组处理的GroupBy方法在List中的使用非常广泛.正式近期一个功能需求中又遇到了,而且是需要Gr ...

  8. LINQ使用Lambda表达式选择几列

    学习LINQ的Lambda的表达式,尝试从数据集合中,选择其中几列. 创建一个model: source code: namespace Insus.NET.Models { public class ...

  9. Linq之Lambda表达式

    一 什么是LINQ? LINQ即Language Integrated Query(语言集成查询),LINQ是集成到C#和Visual Basic.NET这些语言中用于提供查询数据能力的一个新特性. ...

随机推荐

  1. Intellij idea 系列教程之破解方法

    Intellij idea 系列教程之破解方法 Intellij idea 系列教程目录(https://www.cnblogs.com/binarylei/p/10347600.html) 到这个地 ...

  2. PHP 判断字符串括号是否匹配

    <?php function aa($str) { $temp = array(); for ($i = 0; $i < strlen($str); $i++) { $t = $str[$ ...

  3. nginx域名转发 负载均衡 反向代理

    公司有三台机器在机房,因为IP不够用,肯定要分出来,所以要建立单IP 多域名的反向代理, 就是当请求www.abc.com 跳转到本机, 请求www.bbc.com 跳转到192.168.0.35 机 ...

  4. PreparedStatement批量处理和事务

    PreparedStatement批量处理和事务代码如下: /* * PreparedStatement: 1.addBatch() 将一组参数添加到 PreparedStatement对象内部 2. ...

  5. Python : locals and globals

    Python有两个内置的函数,locals() 和globals(),它们提供了基于字典的访问局部和全局变量的方式.Python使用叫做名字空间的东西来记录变量的轨迹.名字空间只是一个 字典,它的键字 ...

  6. 在WebGrid中做 批量删除操作

    一般的MVC WebGrid都是在每一行中加入 Edit Detail Delete 这些Link 去对每条记录去单独操作. 稍微研究了一下总结一个 做批量删除的办法. 1. 首先是在WebGrid中 ...

  7. Windows-universal-samples学习笔记系列三:Navigation

    Navigation Back Button Master/detail Navigation menu (XAML) Pivot Projection XHR, handling navigatio ...

  8. spring学习九 spring aop详解

    本文来自于:https://www.cnblogs.com/jingzhishen/p/4980551.html AOP(Aspect-Oriented Programming,面向方面编程),可以说 ...

  9. centos6中搭建tomcat

    一.安装jdk [root@tomcat ~]# yum -y list java* Loaded plugins: fastestmirror, security Loading mirror sp ...

  10. 58.UIScrollView XIB拖拽约束

    第一步: 拖拽UIScrollView 到控制器上 ,给scrollView 添加约束 ,这时是正常的 第二步:scrollview上添加UIview ,(注意:这个 ScrollView就是根据这个 ...