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; }
    }
}

 

转载于:https://www.cnblogs.com/honghong75042/p/3434182.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值