zoukankan      html  css  js  c++  java
  • C#排序 转

    本文链接:https://blog.csdn.net/fysuccess/article/details/36416255
    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>();
     ———————————————— 
    版权声明:本文为CSDN博主「fysuccess」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/fysuccess/article/details/36416255
  • 相关阅读:
    oracle 创建数据库 创建表空间 创建用户
    Oracle 10G/11G 导入 导出
    winform与IE交互
    asihttprequest简单异步
    架构师的故事
    duobangotinySDP,rfc 2327
    duobangotinySAK,20121213
    doubango框架阅读计划
    并读<自己动手做操作系统>及<汇编语言2>
    SBJSON在xcode的应用中需要注意的
  • 原文地址:https://www.cnblogs.com/hjj-fighting/p/11377623.html
Copyright © 2011-2022 走看看