BT

Jonathan Allen on Equality Operator Overloading

| by James Vastbinder Follow 0 Followers on Nov 29, 2007. Estimated reading time: less than one minute |

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

Tell us what you think

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

Email me replies to any of my messages in this thread

What about IEqualityComparer? by Pierre Cart-Grandjean

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

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

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

Email me replies to any of my messages in this thread

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

Email me replies to any of my messages in this thread

3 Discuss
BT