Say you have two different classes where each have their own implementation of Equals; which one is used? What if only one of them have one? Or none of them? Are any of the following lines equivalent?
object .Equals( first, second ) first .Equals( second ) second .Equals( first )
I'm guessing that the first two might be equivalent, but I don't really have a clue.
What does it really do?
Basically it does three things:
first.Equals(second)
The ordering shouldn't matter if both values have well-behaved equality implementations, as equality should be implemented such that x.Equals(y)
implies y.Equals(x)
. However, the offline documentation I've got installed does state that first.Equals(second) (or objA.equals(objB) to use the real parameter naming) is specified. The online documentation doesn't mention this, interestingly enough.
Just to make all of this concrete, the implementation could look like this:
public static bool Equals(object x, object y) { if (x == y) // Reference equality only; overloaded operators are ignored { return true; } if (x == null || y == null) // Again, reference checks { return false; } return x.Equals(y); // Safe as we know x != null. }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With