# IStructuralEquatable.Equals(Object, IEqualityComparer) メソッド

## 定義

オブジェクトが現在のインスタンスと構造的に等しいかどうかを判断します。

``````public:
bool Equals(System::Object ^ other, System::Collections::IEqualityComparer ^ comparer);``````
``public bool Equals (object other, System.Collections.IEqualityComparer comparer);``
``public bool Equals (object? other, System.Collections.IEqualityComparer comparer);``
``abstract member Equals : obj * System.Collections.IEqualityComparer -> bool``
``Public Function Equals (other As Object, comparer As IEqualityComparer) As Boolean``

#### パラメーター

other
Object

comparer
IEqualityComparer

#### 戻り値

2 つのオブジェクトが等しい場合は `true`。それ以外の場合は `false`

## 例

``````using System;
using System.Collections;
using System.Collections.Generic;

public class NanComparer : IEqualityComparer
{
public new bool Equals(object x, object y)
{
if (x is float)
return (float) x == (float) y;
else if (x is double)
return (double) x == (double) y;
else
return EqualityComparer<object>.Default.Equals(x, y);
}

public int GetHashCode(object obj)
{
return EqualityComparer<object>.Default.GetHashCode(obj);
}
}
``````
``````Imports System.Collections
Imports System.Collections.Generic

Public Class NanComparer : Implements IEqualityComparer
Public Overloads Function Equals(x As Object, y As Object) As Boolean _
Implements IEqualityComparer.Equals
If TypeOf x Is Single Then
Return CSng(x) = CSng(y)
ElseIf TypeOf x Is Double Then
Return CDbl(x) = CDbl(y)
Else
Return EqualityComparer(Of Object).Default.Equals(x, y)
End If
End Function

Public Overloads Function GetHashCode(obj As Object) As Integer _
Implements IEqualityComparer.GetHashCode
Return EqualityComparer(Of Object).Default.GetHashCode(obj)
End Function
End Class
``````

``````public class Example
{
public static void Main()
{
var t1 = Tuple.Create(12.3, Double.NaN, 16.4);
var t2 = Tuple.Create(12.3, Double.NaN, 16.4);

// Call default Equals method.
Console.WriteLine(t1.Equals(t2));

IStructuralEquatable equ = t1;
// Call IStructuralEquatable.Equals using default comparer.
Console.WriteLine(equ.Equals(t2, EqualityComparer<object>.Default));

// Call IStructuralEquatable.Equals using
// StructuralComparisons.StructuralEqualityComparer.
Console.WriteLine(equ.Equals(t2,
StructuralComparisons.StructuralEqualityComparer));

// Call IStructuralEquatable.Equals using custom comparer.
Console.WriteLine(equ.Equals(t2, new NanComparer()));
}
}
// The example displays the following output:
//       True
//       True
//       True
//       False
``````
``````Module Example
Public Sub Main()
Dim t1 = Tuple.Create(12.3, Double.NaN, 16.4)
Dim t2 = Tuple.Create(12.3, Double.NaN, 16.4)

' Call default Equals method.
Console.WriteLine(t1.Equals(t2))

Dim equ As IStructuralEquatable = t1
' Call IStructuralEquatable.Equals using default comparer.
Console.WriteLine(equ.Equals(t2, EqualityComparer(Of Object).Default))

' Call IStructuralEquatable.Equals using
' StructuralComparisons.StructuralEqualityComparer.
Console.WriteLine(equ.Equals(t2,
StructuralComparisons.StructuralEqualityComparer))

' Call IStructuralEquatable.Equals using custom comparer.
Console.WriteLine(equ.Equals(t2, New NanComparer))
End Sub
End Module
' The example displays the following output:
'       True
'       True
'       True
'       False
``````

## 注釈

メソッドは Equals 、配列オブジェクトとタプル オブジェクトのカスタム構造比較をサポートします。 次に、このメソッドは オブジェクトの メソッドを `comparer` 呼び出して、最初の IEqualityComparer.Equals 要素またはコンポーネントから始まる個々の配列要素またはタプル コンポーネントを比較します。 メソッド呼び出しが返されたとき、IStructuralEquatable.Equalsまたはすべての配列要素またはタプル コンポーネントが比較された後に、終了するIEqualityComparer.Equals個々の`false`呼び出しと メソッドが値を返します。