码迷,mamicode.com
首页 > Windows程序 > 详细

C# 重写Equals

时间:2019-01-14 18:49:08      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:contains   rman   str   temp   exce   eid   ima   for   override   

public class PerformanceRank
        {
            public int Rank { get; set; }

            public string Eid { get; set; }

            public string Name { get; set; }

            public decimal Money { get; set; }

            //重写Equals方法

            public override bool Equals(object obj)
            {
                if (obj == null)
                {
                    return false;
                }
                if ((obj.GetType().Equals(this.GetType())) == false)
                {
                    return false;
                }
                PerformanceRank temp = null;
                temp = (PerformanceRank)obj;

                //因为取差集,不用rank,就不写rank
                return this.Eid.Equals(temp.Eid) && this.Name.Equals(temp.Name) && this.Money.Equals(temp.Money);                

            }

            //重写GetHashCode方法(重写Equals方法必须重写GetHashCode方法,否则发生警告

            public override int GetHashCode()
            {
                return this.Eid.GetHashCode() + this.Name.GetHashCode() + this.Money.GetHashCode();              
            }
        }

  

    wtr.ItemsSource = week_top_rank;
    //wbr.ItemsSource = week_bottom_rank.Except(week_top_rank).ToList(); //排除重复的数据
    wbr.ItemsSource = week_bottom_rank.Where(d => !week_top_rank.Contains(d)); //排除重复的数据
    mtr.ItemsSource = month_top_rank;
    mbr.ItemsSource = month_bottom_rank.Except(month_top_rank).ToList(); //排除重复的数据

  

C# 重写Equals

标签:contains   rman   str   temp   exce   eid   ima   for   override   

原文地址:https://www.cnblogs.com/BGHAdmin/p/10268185.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!