What's the difference between IComparable & IEquatable interfaces?

后端 未结 5 944
星月不相逢
星月不相逢 2020-12-07 14:25

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

5条回答
  •  [愿得一人]
    2020-12-07 15:12

    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 you very definitely want the consumer to infer that just because CompareTo() returns zero, this does not imply that the objects are equal (for anything other than sorting purposes).

提交回复
热议问题