Why aren't IStructuralEquatable and IStructura

2020-07-09 02:56发布

问题:

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

回答1:

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.