Tuple<T1,T2,T3>.Equals(Object) メソッド

定義

現在の Tuple<T1,T2,T3> オブジェクトが、指定されたオブジェクトと等しいかどうかを示す値を返します。

public:
 override bool Equals(System::Object ^ obj);
public override bool Equals (object obj);
public override bool Equals (object? obj);
override this.Equals : obj -> bool
Public Overrides Function Equals (obj As Object) As Boolean

パラメーター

obj
Object

このインスタンスと比較するオブジェクト。

戻り値

現在のインスタンスが指定したオブジェクトと等しい場合は true。それ以外の場合は false

次の例では、 メソッドを Tuple<T1,T2,T3>.Equals(Object) 呼び出して、オブジェクトの配列 Tuple<T1,T2,T3> 内のオブジェクトが互いに等しいかどうかを判断します。 出力には、コンポーネントが等しい値をEquals(Object)持つオブジェクトをTuple<T1,T2,T3>比較するときに メソッドがを返trueすという事実が反映されます。

using System;

public class Example
{
   public static void Main()
   {
      Tuple<string, double, int>[] scores = 
                      { Tuple.Create("Ed", 78.8, 8),
                        Tuple.Create("Abbey", 92.1, 9), 
                        Tuple.Create("Ed", 71.2, 9),
                        Tuple.Create("Sam", 91.7, 8), 
                        Tuple.Create("Ed", 71.2, 5),
                        Tuple.Create("Penelope", 82.9, 8),
                        Tuple.Create("Ed", 71.2, 9),
                        Tuple.Create("Judith", 84.3, 9) };

      // Test each tuple object for equality with every other tuple.
      for (int ctr = 0; ctr < scores.Length; ctr++)
      {
         var currentTuple = scores[ctr];
         for (int ctr2 = ctr + 1; ctr2 < scores.Length; ctr2++)
            Console.WriteLine("{0} = {1}: {2}", currentTuple, scores[ctr2], 
                                                currentTuple.Equals(scores[ctr2]));      

         Console.WriteLine();
      }   
   }
}
// The example displays the following output;
//    (Ed, 78.8, 8) = (Abbey, 92.1, 9): False
//    (Ed, 78.8, 8) = (Ed, 71.2, 9): False
//    (Ed, 78.8, 8) = (Sam, 91.7, 8): False
//    (Ed, 78.8, 8) = (Ed, 71.2, 5): False
//    (Ed, 78.8, 8) = (Penelope, 82.9, 8): False
//    (Ed, 78.8, 8) = (Ed, 71.2, 9): False
//    (Ed, 78.8, 8) = (Judith, 84.3, 9): False
//    
//    (Abbey, 92.1, 9) = (Ed, 71.2, 9): False
//    (Abbey, 92.1, 9) = (Sam, 91.7, 8): False
//    (Abbey, 92.1, 9) = (Ed, 71.2, 5): False
//    (Abbey, 92.1, 9) = (Penelope, 82.9, 8): False
//    (Abbey, 92.1, 9) = (Ed, 71.2, 9): False
//    (Abbey, 92.1, 9) = (Judith, 84.3, 9): False
//    
//    (Ed, 71.2, 9) = (Sam, 91.7, 8): False
//    (Ed, 71.2, 9) = (Ed, 71.2, 5): False
//    (Ed, 71.2, 9) = (Penelope, 82.9, 8): False
//    (Ed, 71.2, 9) = (Ed, 71.2, 9): True
//    (Ed, 71.2, 9) = (Judith, 84.3, 9): False
//    
//    (Sam, 91.7, 8) = (Ed, 71.2, 5): False
//    (Sam, 91.7, 8) = (Penelope, 82.9, 8): False
//    (Sam, 91.7, 8) = (Ed, 71.2, 9): False
//    (Sam, 91.7, 8) = (Judith, 84.3, 9): False
//    
//    (Ed, 71.2, 5) = (Penelope, 82.9, 8): False
//    (Ed, 71.2, 5) = (Ed, 71.2, 9): False
//    (Ed, 71.2, 5) = (Judith, 84.3, 9): False
//    
//    (Penelope, 82.9, 8) = (Ed, 71.2, 9): False
//    (Penelope, 82.9, 8) = (Judith, 84.3, 9): False
//    
//    (Ed, 71.2, 9) = (Judith, 84.3, 9): False
open System

let scores = 
    [| Tuple.Create("Ed", 78.8, 8)
       Tuple.Create("Abbey", 92.1, 9)
       Tuple.Create("Ed", 71.2, 9)
       Tuple.Create("Sam", 91.7, 8)
       Tuple.Create("Ed", 71.2, 5)
       Tuple.Create("Penelope", 82.9, 8)
       Tuple.Create("Ed", 71.2, 9)
       Tuple.Create("Judith", 84.3, 9) |]

// Test each tuple object for equality with every other tuple.
for ctr = 0 to scores.Length - 1 do
    let currentTuple = scores[ctr]
    for ctr2 = ctr + 1 to scores.Length - 1 do
        printfn $"{currentTuple} = {scores[ctr2]}: {currentTuple.Equals scores[ctr2]}"
    printfn ""

// The example displays the following output
//    (Ed, 78.8, 8) = (Abbey, 92.1, 9): False
//    (Ed, 78.8, 8) = (Ed, 71.2, 9): False
//    (Ed, 78.8, 8) = (Sam, 91.7, 8): False
//    (Ed, 78.8, 8) = (Ed, 71.2, 5): False
//    (Ed, 78.8, 8) = (Penelope, 82.9, 8): False
//    (Ed, 78.8, 8) = (Ed, 71.2, 9): False
//    (Ed, 78.8, 8) = (Judith, 84.3, 9): False
//    
//    (Abbey, 92.1, 9) = (Ed, 71.2, 9): False
//    (Abbey, 92.1, 9) = (Sam, 91.7, 8): False
//    (Abbey, 92.1, 9) = (Ed, 71.2, 5): False
//    (Abbey, 92.1, 9) = (Penelope, 82.9, 8): False
//    (Abbey, 92.1, 9) = (Ed, 71.2, 9): False
//    (Abbey, 92.1, 9) = (Judith, 84.3, 9): False
//    
//    (Ed, 71.2, 9) = (Sam, 91.7, 8): False
//    (Ed, 71.2, 9) = (Ed, 71.2, 5): False
//    (Ed, 71.2, 9) = (Penelope, 82.9, 8): False
//    (Ed, 71.2, 9) = (Ed, 71.2, 9): True
//    (Ed, 71.2, 9) = (Judith, 84.3, 9): False
//    
//    (Sam, 91.7, 8) = (Ed, 71.2, 5): False
//    (Sam, 91.7, 8) = (Penelope, 82.9, 8): False
//    (Sam, 91.7, 8) = (Ed, 71.2, 9): False
//    (Sam, 91.7, 8) = (Judith, 84.3, 9): False
//    
//    (Ed, 71.2, 5) = (Penelope, 82.9, 8): False
//    (Ed, 71.2, 5) = (Ed, 71.2, 9): False
//    (Ed, 71.2, 5) = (Judith, 84.3, 9): False
//    
//    (Penelope, 82.9, 8) = (Ed, 71.2, 9): False
//    (Penelope, 82.9, 8) = (Judith, 84.3, 9): False
//    
//    (Ed, 71.2, 9) = (Judith, 84.3, 9): False
Module Example
   Public Sub Main()
      Dim scores() = 
              { Tuple.Create("Ed", 78.8, 8),
                Tuple.Create("Abbey", 92.1, 9), 
                Tuple.Create("Ed", 71.2, 9),
                Tuple.Create("Sam", 91.7, 8), 
                Tuple.Create("Ed", 71.2, 5),
                Tuple.Create("Penelope", 82.9, 8),
                Tuple.Create("Ed", 71.2, 9),
                Tuple.Create("Judith", 84.3, 9) }

      ' Test each tuple object for equality with every other tuple.
      For ctr As Integer = 0 To scores.Length - 1
         Dim currentTuple = scores(ctr)
         For ctr2 As Integer = ctr + 1 To scores.Length - 1
            Console.WriteLine("{0} = {1}: {2}", currentTuple, scores(ctr2), 
                                                currentTuple.Equals(scores(ctr2)))      
         Next
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output;
'    (Ed, 78.8, 8) = (Abbey, 92.1, 9): False
'    (Ed, 78.8, 8) = (Ed, 71.2, 9): False
'    (Ed, 78.8, 8) = (Sam, 91.7, 8): False
'    (Ed, 78.8, 8) = (Ed, 71.2, 5): False
'    (Ed, 78.8, 8) = (Penelope, 82.9, 8): False
'    (Ed, 78.8, 8) = (Ed, 71.2, 9): False
'    (Ed, 78.8, 8) = (Judith, 84.3, 9): False
'    
'    (Abbey, 92.1, 9) = (Ed, 71.2, 9): False
'    (Abbey, 92.1, 9) = (Sam, 91.7, 8): False
'    (Abbey, 92.1, 9) = (Ed, 71.2, 5): False
'    (Abbey, 92.1, 9) = (Penelope, 82.9, 8): False
'    (Abbey, 92.1, 9) = (Ed, 71.2, 9): False
'    (Abbey, 92.1, 9) = (Judith, 84.3, 9): False
'    
'    (Ed, 71.2, 9) = (Sam, 91.7, 8): False
'    (Ed, 71.2, 9) = (Ed, 71.2, 5): False
'    (Ed, 71.2, 9) = (Penelope, 82.9, 8): False
'    (Ed, 71.2, 9) = (Ed, 71.2, 9): True
'    (Ed, 71.2, 9) = (Judith, 84.3, 9): False
'    
'    (Sam, 91.7, 8) = (Ed, 71.2, 5): False
'    (Sam, 91.7, 8) = (Penelope, 82.9, 8): False
'    (Sam, 91.7, 8) = (Ed, 71.2, 9): False
'    (Sam, 91.7, 8) = (Judith, 84.3, 9): False
'    
'    (Ed, 71.2, 5) = (Penelope, 82.9, 8): False
'    (Ed, 71.2, 5) = (Ed, 71.2, 9): False
'    (Ed, 71.2, 5) = (Judith, 84.3, 9): False
'    
'    (Penelope, 82.9, 8) = (Ed, 71.2, 9): False
'    (Penelope, 82.9, 8) = (Judith, 84.3, 9): False
'    
'    (Ed, 71.2, 9) = (Judith, 84.3, 9): False

注釈

パラメーターは obj 、次の条件で現在のインスタンスと等しいと見なされます。

  • これは オブジェクトです Tuple<T1,T2,T3>

  • その 3 つのコンポーネントは、現在のインスタンスと同じ型です。

  • その 3 つのコンポーネントは、現在のインスタンスのコンポーネントと等しくなります。 等しいかどうかは、各コンポーネントの既定のオブジェクトの等値比較子によって判断されます。

適用対象