A simple question:
I want to compare two objects using the virtual Equals() method (not ==). Both can be null.
Should I repeat this litany:
if ((left == null && right == null) || (left != null && left.Equals(right)) {
}
or is there a more elegant idiom for such situation?
Yup:
or even without making it obvious that it’s calling the static method:
(Personally I prefer the extra clarity though.)
The static
object.Equalsmethod doesn’t have terribly good documentation, but it does exactly what you want 🙂