C# 2.0: 3f.Equals(3) != 3.Equals(3f)

In C#, it is good practice to make the Equals method commute.  But even the Base Class Library fails to do this sometimes.  It’s possible to have a.Equals(b) != b.Equals(a) even with primitive types, e.g, when a is a Single (a float) and b is an Int32.

http://blogs.msdn.com/jmstall/archive/2005/03/23/401038.aspx

Leave a Reply