tags:

views:

112

answers:

1

the reason I asked the question was because after reading the msdn advice on overloading this operator at the end of the page it mentioned:

A common error in overloads of operator == is to use (a == b), (a == null), or (b == null) to check for reference equality. This instead results in a call to the overloaded operator ==, causing an infinite loop. Use ReferenceEquals or cast the type to Object, to avoid the loop.

so I was wondering if I should implement the overload for the standard scenario.

+10  A: 

No! Do not mess with reference equality unless you know what you are doing. Implement IComparable Equals method if you need to.

Edit: For a better picture look up Effective C#, Item #9.

Edit: You can get to it from here:

http://my.safaribooksonline.com/0321245660/ch01lev1sec10

Hamish Grubijan
I've already implemented the IComparable method. I just need claification on whetehr or not I need to implement the overload for the standard case scenario as well as for my specific case scenario, but of no one is brave enough to break c# I will :)
Dark Star1
Reference equality is already given to you. Since references are *like* pointers, the .Net platform can just compare the two. You will introduce risk and slowdown with no added benefit. Don't do it. Now object equality cannot be done automatically and without your help. Also look into soft references, but I doubt that you need them.
Hamish Grubijan
dumped the implement after reading about the pitfallls of GetHashCode.:)
Dark Star1