zoukankan      html  css  js  c++  java
  • List的Sort自定义排序实例

    List<UnRecruitInfo> recreuitList = dic["招聘会"] as List<UnRecruitInfo>;
                    //需要对招聘会的列表重新排序
                    //排序规则:召开时间>=今天的,进行顺排(从今天到将来),其他的顺序不变(从今天到过去,即过期的)
                    DateTime now = DateTime.Parse(DateTime.Now.ToShortDateString()),
                             aTime,
                             bTime;
                    recreuitList.Sort(delegate(UnRecruitInfo a, UnRecruitInfo b)
                    {//排序开始
                        aTime = DateTime.Parse(a.RecTime.ToShortDateString());
                        bTime = DateTime.Parse(b.RecTime.ToShortDateString());
                        if (a.RecTime >= now && b.RecTime >= now)
                        {//顺排(从小到大)

                            if (aTime < bTime) return -1;
                            else if (aTime > bTime) return 1;
                            else return 0;
                        }
                        else
                        {//倒排(从大到小)
                            if (aTime < bTime) return 1;
                            else if (aTime > bTime) return -1;
                            else return 0;
                        }
                    });
                    rptZQZP.DataSource = recreuitList;
                    rptZQZP.DataBind();

  • 相关阅读:
    Python之面向对象新式类和经典类
    Python之面向对象继承和派生
    Python之面向对象类和对象
    Python之面向对象的程序设计
    Python之面向对象函数式编程
    Python之内置函数
    列表解析与生成器表达式
    03: 交换机基本原理与配置
    02: 网络布线与数制转换
    01:数据封装解封的过程
  • 原文地址:https://www.cnblogs.com/Denny_Yang/p/2054070.html
Copyright © 2011-2022 走看看