What are the best practices for implementing the == operator for a class in C#?

Posted by remio on Stack Overflow See other posts from Stack Overflow or by remio
Published on 2009-10-06T11:12:12Z Indexed on 2010/04/08 3:33 UTC
Read the original article Hit count: 136

While implementing an == operator, I have the feeling that I am missing some essential points.
Hence, I am searching some best practices around that.
Here are some related questions I am thinking about:

  • How to cleanly handle the reference comparison?
  • Should it be implemented through a IEquatable<T>-like interface? Or overriding object.Equals?
  • And what about the != operator?

(this list might not be exhaustive).

© Stack Overflow or respective owner

Related posts about c#

Related posts about operators