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) 方法會傳回兩個物件 xytrue,則 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 兩個物件 xy (如果 yxtrue)。對於 xy true 的兩個物件 xz,以及 trueyz,也 trueThat 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.

適用於