为什么IStructuralEquatable和IStructuralComparable通用?

时间:2021-03-04 23:00:44

System.Collections.IStructuralEquatable and System.Collections.IStructuralComparable were added in .NET 4, but why aren't they generic, like IEquatable<T> and IComparable<T>?

System.Collections。IStructuralEquatable System.Collections。在。net 4中添加了IStructuralComparable,但是为什么它们不是通用的,比如IEquatable 和icom寓言 ?

1 个解决方案

#1


4  

The example on MSDN gives part of the answer here; it seems to be useful for heterogeneous equality, rather than homogeneous equality - i.e. for testing whether two objects (/values) of potentially different types should be considered equal. In such scenarios, it is extremely likely that the calling code is dealing with object (to represent heterogeneous data). And generic methods don't play nicely then.

MSDN上的例子给出了部分答案;它似乎对异类的平等有用,而不是同质的平等——也就是说,用于测试潜在不同类型的两个对象(/值)是否应该被认为是相等的。在这种情况下,调用代码非常可能处理对象(表示异构数据)。一般的方法都不太好。

#1


4  

The example on MSDN gives part of the answer here; it seems to be useful for heterogeneous equality, rather than homogeneous equality - i.e. for testing whether two objects (/values) of potentially different types should be considered equal. In such scenarios, it is extremely likely that the calling code is dealing with object (to represent heterogeneous data). And generic methods don't play nicely then.

MSDN上的例子给出了部分答案;它似乎对异类的平等有用,而不是同质的平等——也就是说,用于测试潜在不同类型的两个对象(/值)是否应该被认为是相等的。在这种情况下,调用代码非常可能处理对象(表示异构数据)。一般的方法都不太好。