IEqualityComparer<T>.Equals(T, T) 方法

定义

确定指定的对象是否相等。Determines whether the specified objects are equal.

public:
 bool Equals(T x, T y);
public bool Equals (T x, T y);
abstract member Equals : 'T * 'T -> bool
Public Function Equals (x As T, y As T) As Boolean

参数

x
T

要比较的第一个类型为 T 的对象。The first object of type T to compare.

y
T

要比较的第二个类型为 T 的对象。The second object of type T to compare.

返回

Boolean

如果指定的对象相等,则为 true;否则为 falsetrue if the specified objects are equal; otherwise, false.

注解

实现此方法可以为类型提供自定义相等性比较 TImplement this method to provide a customized equality comparison for type T.

实施者说明

实现需要确保如果 Equals(T, T) 方法 true 为两个对象 x 和返回 y ,则的方法返回的值 GetHashCode(T) x 必须等于为返回的值 yImplementations 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.

Equals(T, T)方法为自反、对称和可传递。The Equals(T, T) method is reflexive, symmetric, and transitive. 也就是说, true 如果用于将一个对象与其自身进行比较,则返回; 对于两个对象,则返回; 对于和,则返回; 对于和,则返回 true x y true y x true x z true x y true y zThat 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.

适用于