[英]Why does IEqualityComparer<T> Equals method take two arguments?
I don't understand why does the Equals method take (T x, T y). 我不明白为什么Equals方法需要(T x,T y)。 Don't you already have one instance to compare to when you invoke the method on an instance?
在实例上调用该方法时,您是否已经没有一个实例可以与之进行比较? Same for GetHashCode - why does it need an object instance as a parameter if I'm already invoking it on an existing instance?
与GetHashCode相同-如果我已经在现有实例上调用对象实例,为什么它需要一个对象实例作为参数?
What would happen if I invoke a.GetHashCode(b)? 如果我调用a.GetHashCode(b)会发生什么? Which one is used?
使用哪一个?
The IEqualityComparer<T>
interface is for a comparer object. IEqualityComparer<T>
接口用于比较器对象。 So, no...you would not already have one instance as part of the implementation. 因此,不...您将没有一个实例作为实现的一部分。
You may be thinking of IEquatable<T>
, where it's implemented by the type of object being compared. 您可能会想到
IEquatable<T>
,它是由要比较的对象的类型实现的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.