What's the difference between IComparable & IEquatable interfaces?

后端 未结 5 945
星月不相逢
星月不相逢 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:08

    As stated on the MSDN Page for IEquatable:

    The IComparable interface defines the CompareTo method, which determines the sort order of instances of the implementing type. The IEquatable interface defines the Equals method, which determines the equality of instances of the implementing type.

    Equals vs. CompareTo

提交回复
热议问题