首页 > Windows开发 > 详细

C# 重写Equals

时间:2019-01-14 18:39:16      阅读:219      评论:0      收藏:0      [点我收藏+]
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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!