IComparable 和有什么区别?IEquatable 接口? [英] What's the difference between IComparable & IEquatable interfaces?

查看:22
本文介绍了IComparable 和有什么区别?IEquatable 接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两个接口似乎都比较对象是否相等,那么它们之间的主要区别是什么?

Both the interfaces seem to compare objects for equality, so what are the major differences between them?

推荐答案

IEquatable 测试两个对象是否相等.

IEquatable tests whether two objects are equal.

IComparable 对被比较的对象进行总排序.

IComparable imposes a total ordering on the objects being compared.

例如,IEquatable 会告诉你 5 不等于 7.IComparable 会告诉你 5 在 7 之前.

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

这篇关于IComparable 和有什么区别?IEquatable 接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆