What's the difference between IComparable & IEquatable interfaces?

SoftwareGeek picture SoftwareGeek · Mar 9, 2010 · Viewed 18.2k times · Source

both the interfaces seem to compare objects for equality, so what's the major differences between them?

Answer

Greg D picture Greg D · Mar 9, 2010

IEquatable tests whether two objects are equal.

IComparable imposes a total ordering on the objects being compared.

For example, IEquatable would tell you that 5 is not equal to 7. IComparable would tell you that 5 comes before 7.