both the interfaces seem to compare objects for equality, so what's the major differences between them?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
IEquatable<T>
for equality.IComparable<T>
for ordering.As stated on the MSDN Page for IEquatable:
Equals
vs.CompareTo
In addition to Greg D's answer:
You might implement IComparable without implementing IEquatable for a class where a partial ordering makes sense, and where very definitely you wish the consumer to draw the inference that just because CompareTo() returns zero, this does not imply that the objects are equal (for anything other than sorting purposes).
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.