为什么不IStructuralEquatable和IStructuralComparable通用?IStructuralEquatable、IStructuralComparable

2023-09-03 07:36:09 作者:野性随风.

System.Collections.IStructuralEquatable System.Collections.IStructuralComparable 添加在.NET 4中,但为什么AREN 'T他们通用的,如 IEquatable< T> IComparable的< T>

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

推荐答案

的的例如在MSDN上这里给出了部分答案;这似乎是异质的平等,而不是均匀相等有用的 - 即用于测试是否的可能不同的类型的应该被视为相等的两个对象(/值)。在这样的情况下,这是非常有可能调用code是处理对象(重新present异构数据)。而通用的方法不玩了很好的话。

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.