Sign in to follow this  
Quat

[.net] Equals and value types

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this