EqualityComparer<T>.Equals(T, T) 方法
定义
当在派生类中被重写时,确定两个类型为 T 的对象是否相等。When overridden in a derived class, determines whether two objects of type T are equal.
public:
abstract bool Equals(T x, T y);
public abstract bool Equals (T x, T y);
public abstract bool Equals (T? x, T? y);
override this.Equals : 'T * 'T -> bool
Public MustOverride Function Equals (x As T, y As T) As Boolean
参数
- x
- T
要比较的第一个对象。The first object to compare.
- y
- T
要比较的第二个对象。The second object to compare.
返回
如果指定的对象相等,则为 true;否则为 false。true if the specified objects are equal; otherwise, false.
实现
注解
Equals方法为自反、对称和可传递。The Equals method is reflexive, symmetric, and transitive. 也就是说, true 如果用于将一个对象与其自身进行比较,则返回; 对于两个对象,则返回; 对于和,则返回; 对于和,则返回 true x y true y x true x z true x y true y z 。That is, it returns true if used to compare an object with itself; true for two objects x and y if it is true for y and x; and true for two objects x and z if it is true for x and y and also true for y and z.
实施者说明
实现需要确保如果 Equals(T, T) 方法 true 为两个对象 x 和返回 y ,则的方法返回的值 GetHashCode(T) x 必须等于为返回的值 y 。Implementations are required to ensure that if the Equals(T, T) method returns true for two objects x and y, then the value returned by the GetHashCode(T) method for x must equal the value returned for y.