What's the difference between IComparable & IEquatable interfaces?

后端 未结 5 956
星月不相逢
星月不相逢 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 14:49

    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.

提交回复
热议问题