Compartir a través de


IStructuralEquatable.Equals Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Determines whether an object is structurally equal to the current instance.

Namespace:  System.Collections
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Function Equals ( _
    other As Object, _
    comparer As IEqualityComparer _
) As Boolean
bool Equals(
    Object other,
    IEqualityComparer comparer
)

Parameters

  • other
    Type: System.Object
    The object to compare with the current instance.

Return Value

Type: System.Boolean
true if the two objects are equal; otherwise, false.

Remarks

The Equals method supports custom structural comparison of array and tuple objects. This method in turn calls the comparer object's IEqualityComparer.Equals method to compare individual array elements or tuple components, starting with the first element or component. The individual calls to IEqualityComparer.Equals end and the IStructuralEquatable.Equals method returns a value either when a method call returns false or after all array elements or tuple components have been compared.

Examples

The default equality comparer, EqualityComparer<Object>.Default.Equals, considers two NaN values to be equal. In some cases, however, you may want the comparison of NaN values for equality to return false, which indicates that the values cannot be compared. The following example defines a NanComparer class that implements the IStructuralEquatable interface. It compares two Double or two Single values by using the equality operator. It passes values of any other type to the default equality comparer.

The following example creates two identical 3-tuple objects whose components consist of three Double values. The value of the second component is Double.NaN. The example then calls the Tuple<T1, T2, T3>.Equals method, and it calls the IStructuralEquatable.Equals method twice. The first time, it passes the default equality comparer that is returned by the EqualityComparer<T>.Default property. The second time, it passes the custom NanComparer object. As the output from the example shows, the first two method calls return true, whereas the third call returns false.

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.