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);
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 傳回兩個物件 xy ,則方法所傳回的值 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.

適用於