BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Jonathan Allen on Equality Operator Overloading

Jonathan Allen on Equality Operator Overloading

Bookmarks

In this deep dive article on equal operator overloading Jonathan Allen clears the air on overriding the equality operator. In the article Jonathan provides code samples in both VB and C# to demonstrate the nuances of each .NET language. He also covers usage in both structures and classes.

Areas covered include:

  • The initial Class signature
  • Fields and Properties
  • Type-Safe Equality
  • Hash Codes
  • Overriding the base class Equals method
  • Performance and Testing

Enjoy this well-thought through tutorial on Equality Operator overloading.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • What about IEqualityComparer?

    by Pierre Cart-Grandjean,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Hello,

    In your post you don't mention this interface. And I have to say that so many ways to define the equality puzzle me.

    Cheers,
    Timok

  • When to do this

    by Mat Hobbs,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    You mention "Operator overloading usually makes more sense in structures than in classes..." but it would be useful to point out that for classes then almost never do you want to override Equals() or GetHashCode() except in very specific circumstances. This gets abused a lot...

  • Index Operator Overloading

    by Shawn Zernik,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    The following is how to overload the index operator:

    www.internetworkconsulting.net/how-override-ind...

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT