I've 2 lists of class A
, A
has implemented Equals(object obj)
and GetHashCode()
this 2 methods working correctly, code is below.
class A
{
public string TEST
{
get;
set;
}
public override bool Equals(object obj)
{
return ((A)obj).TEST == this.TEST;
}
public override int GetHashCode()
{
return this.TEST.GetHashCode();
}
}
I have 2 list of this class, firstList = { X1, X2, X3 }
and secondList = { X1, X2, Y1 }
. When I use firstList.Except(secondList)
it always return all of elements in firstList and secondList.Except(firstList)
also return every elements in secondList, as show below.
var test1 = firstList.Except(secondList).ToList(); // test1 = all elements of firstList
var test2 = secondList.Except(firstList).ToList(); // test2 = all elements of secondList
I want to know how can I solving this problem?