I have an IEqualityComparer in c#:
public class ScheduledTimeComparer : IEqualityComparer<ScheduledTime>
{
public bool Equals(ScheduledTime x, ScheduledTime y)
{
if (x == y) return true;
if (x == null) return false;
return GetHashCode(x) == GetHashCode(y);
}
public int GetHashCode(ScheduledTime schedule)
{
return schedule.Start.GetHashCode() ^ schedule.End.GetHashCode();
}
}
public class ScheduledTime
{
public int Start { get; set; }
public int End { get; set; }
}
I have the following 2 list of ScheduledTimes objects:
List1 = [{ Start = 60, End = 120 }]
List2 = [{ Start = 180, End = 240 }, { Start = 60, End = 120 }]
Now when i use the above mentioned equality comparer like:
//Count should be greater than 0 because both List1 and List2 are not equal
var equal = List1.Except(List2, new ScheduledTimeComparer()).Count == 0;
The Count is always zero, What i am doing wrong ?