I have been trying to make my equality definition work but found out that IEqualityComparer does not seem to work whatsoever.
My class:
public class DBTileSimple
{
public int X;
public int Y;
public int Zoom;
public DBTileSimple(int x, int y, int z)
{
X = x;
Y = y;
Zoom = z;
}
}
Testing IEqualityComparer, so it should be equal for any object:
public class TileComparer : IEqualityComparer<DBTileSimple>
{
public bool Equals(DBTileSimple x, DBTileSimple y)
{
return true;
}
public int GetHashCode(DBTileSimple obj)
{
return 1;
}
}
Result:
DBTileSimple t1 = new DBTileSimple(10, 20, 17);
DBTileSimple t2 = new DBTileSimple(10, 20, 17);
Log.Info("t1 and t2 = " + (t1 == t2));
returns t1 and t2 = false
My ultimate goal is to compare two lists with these objects and do logical operations over them (intersection, etc.).
So for example:
DBTileSimple t1 = new DBTileSimple(10, 20, 17);
DBTileSimple t2 = new DBTileSimple(10, 20, 17);
List<DBTileSimple> list1 = new List<DBTileSimple>();
list1.Add(t1);
List<DBTileSimple> list2 = new List<DBTileSimple>();
list2.Add(t2);
list1 = list1.Except(list2).ToList();
Now list1 should be empty but it is not.