If object.ReferenceEquals returns true, should instance.Equals always return true?
Would you think its unexpected behaviour where the output below was pass/fail?
Assert.True(object.ReferenceEquals(obj,obj));
Assert.True(obj.Equals(obj));
Personally I think its strange, and cant really think of a good reason, where an instance should not be equal to itself.
There are two ways to answer your question.
It’s unexpected behavior, yes. A properly-designed class should always return true from
.Equalsif it returns true from.ReferenceEquals. That’s codified in MSDN’s Design Guidelines for Developing Class Libraries, Implementing the Equals Method article:But that requirement is not enforced by the language or runtime. The designer of the class in question is perfectly free to define
Equalsas{ return false; }. Perverse, but possible.