zoukankan      html  css  js  c++  java
  • c# List集合排序

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class ListRate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            List<TicketRuleTimeInfo> list = new List<TicketRuleTimeInfo>  
              {  
                  new TicketRuleTimeInfo("B",1,2,"",0.2m,0.1m),  
                  new TicketRuleTimeInfo("C",1,2,"",0.3m,0.1m), 
                  new TicketRuleTimeInfo("D",1,2,"",0.4m,0.1m), 
                  new TicketRuleTimeInfo("A",1,2,"",0.1m,0.1m), 
              };
            foreach (var item in list)
            {
                Response.Write(item.DepartBA + ":" + item.Rate);
            }
            Console.WriteLine("排序后");
            list.Sort(CompareByRate);
            Response.Write("========================");
            foreach (var item in list)
            {
                Response.Write(item.DepartBA + ":" + item.Rate);
            }
    
    
        }
        public static int CompareByRate(TicketRuleTimeInfo x, TicketRuleTimeInfo y)//从大到小排序器  
        {
            if (x == null)
            {
                if (y == null)
                {
                    return 0;
                }
    
                return 1;
    
            }
            if (y == null)
            {
                return -1;
            }
            int retval = y.Rate.CompareTo(x.Rate);
            return retval;
        }
    }
    public class TicketRuleTimeInfo
    {
        public TicketRuleTimeInfo(string departBA, int minTime, int maxTime, string stadardCabin, decimal rate, decimal lowCharge)
        {
            DepartBA = departBA;
            MinTime = minTime;
            MaxTime = maxTime;
            StandardCabin = stadardCabin;
            Rate = rate;
            LowCharge = LowCharge;
        }
        private string _DepartBA = "before";
        /// <summary>
        /// 起飞前后{before起飞前、after起飞后}
        /// </summary>
        public string DepartBA
        {
            get { return _DepartBA; }
            set { _DepartBA = value; }
        }
        private int _MinTime = 0;
        /// <summary>
        /// 时间区间最低{单位小时hour: 起飞前(DepartTime-XePnrTime)大于MinTime;起飞后System.Math.Abs(DepartTime-XePnrTime)大于MinTime;}
        /// </summary>
        public int MinTime
        {
            get { return _MinTime; }
            set { _MinTime = value; }
        }
        private int _MaxTime = 8760;
        /// <summary>
        /// 时间区间最高{单位小时hour: 起飞前(DepartTime-XePnrTime)小于等于MaxTime;起飞后System.Math.Abs(DepartTime-XePnrTime)小于等于MaxTime;}
        /// </summary>
        public int MaxTime
        {
            get { return _MaxTime; }
            set { _MaxTime = value; }
        }
        private string _StandardCabin = "";
        /// <summary>
        /// 基准舱位
        /// </summary>        
        public string StandardCabin
        {
            get { return _StandardCabin; }
            set { _StandardCabin = value; }
        }
        private decimal _Rate = 0;
        /// <summary>
        /// 费率%
        /// </summary>        
        public decimal Rate
        {
            get { return _Rate; }
            set { _Rate = value; }
        }
        private decimal _LowCharge = 0;
        /// <summary>
        /// 最低手续费{单位元}
        /// </summary>        
        public decimal LowCharge
        {
            get { return _LowCharge; }
            set { _LowCharge = value; }
        }
    }
  • 相关阅读:
    Python标准模块--concurrent.futures 进程池线程池终极用法
    线程,线程池
    常用英文单词
    进程池
    三种方法实现 生产者消费者模型
    进程间通信IPC -- 管道, 队列
    jquery 和 css 属性
    javascript的 Object 和 Function
    nodejs 返回html页面--使用 ejs 模板
    jquery属性
  • 原文地址:https://www.cnblogs.com/honghong75042/p/3434182.html
Copyright © 2011-2022 走看看