C# 重寫Equals

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(); //排除重複的數據ide

相關文章
相關標籤/搜索