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.

返回

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

注解

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

实施者说明

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

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

适用于