IEqualityComparer<T>.Equals(T, T) IEqualityComparer<T>.Equals(T, T) IEqualityComparer<T>.Equals(T, T) IEqualityComparer<T>.Equals(T, T) Method

定義

判斷指定的物件是否相等。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 的第一個物件。The first object of type T to compare.

y

要比較之型別 T 的第二個物件。The second object of type T to compare.

傳回

如果指定的物件相等則為 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兩個物件xy,然後將所傳回的值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.

Equals(T, T)方法是自反、 對稱的且可轉移。The Equals(T, T) method is reflexive, symmetric, and transitive. 也就是說,它會傳回true如果用來比較物件與本身;true兩個物件xytrueyx; 和true兩個物件xztruexytrueyzThat 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.

適用於