Jump to content
  • Advertisement
Sign in to follow this  
Quat

[.net] Equals and value types

This topic is 3762 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!