• Advertisement
Sign in to follow this  

[.net] Equals and value types

This topic is 3518 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my book they give a sample Complex class implementation and it implements: override bool Equals(object rhs) {...} public book Equals(Complex rhs) // IEquatable<Complex> {...} public static bool operator==(Complex lhs, Complex rhs) {...} My question is, what is the point of implementing Equals when operator== is defined? Also, when would the "object" version of Equals ever be called instead of the specific type version? Obviously it would be called if you passed an object, but I can't see why that would ever happen in practice.

Share this post


Link to post
Share on other sites
Advertisement
Implementing Equals() allows for equality comparison in a more general context (for example when working with boxed System.Objects containing the class or generics that cannot be suitably contained).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement