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();

  • 相关阅读:
    redhat 7.6 常用命令
    redhat 7.6 VI编辑操作
    redhat 7.6 网络配置
    华为学习配置笔记-01 配置con密码
    redhat 7.6 ssh 服务配置
    web前端面试第一次[addEventListenr();绑定事件]
    redis集群搭建
    linux服务器重启后redis数据丢失问题
    redis日志文件路径的设置
    linux下redis安装使用
  • 原文地址:https://www.cnblogs.com/Denny_Yang/p/2054070.html
Copyright © 2011-2022 走看看