I am trying to add an equals function to compare two structs, but i am not sure the correct way to write it, or whether both of these functions are valid.
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
Tile other = (Tile) obj;
return other == this;
}
And
public override bool Equals(object obj)
{
if (obj is Tile other)
{
return other == this;
}
return false;
}
My == operator is:
public static bool operator ==(Tile a, Tile b)
{
return a.X == b.X && b.Z == a.Z;
}
Are these functions the same or are they different in subtle ways that i might not be aware of?