Condividi tramite


Tuple<T1,T2,T3,T4,T5>.Equals(Object) Metodo

Definizione

Restituisce un valore che indica se l'oggetto Tuple<T1,T2,T3,T4,T5> corrente è uguale a un oggetto specificato.

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

Parametri

obj
Object

Oggetto da confrontare con questa istanza.

Restituisce

true se l'istanza corrente è uguale all'oggetto specificato; in caso contrario, false.

Esempio

L'esempio seguente definisce una matrice di 5 oggetti tupla che contengono dati sulle temperature dei pazienti in due gruppi di test. Il primo componente della matrice fornisce il numero del gruppo di test e il secondo e il quinto componente forniscono le temperature di un paziente a intervalli orari. Il Tuple<T1,T2,T3,T4,T5>.Equals(Object) metodo viene chiamato per confrontare ogni Tuple<T1,T2,T3,T4,T5> oggetto con ogni altro Tuple<T1,T2,T3,T4,T5> oggetto. L'output illustra che il Equals metodo restituisce true solo quando tutti e cinque i componenti degli Tuple<T1,T2,T3,T4,T5> oggetti hanno valori uguali.

using System;

public class Class1
{
   public static void Main()
   {
      Tuple<int, double, double, double, double>[] temperatureInfos = 
                           { Tuple.Create(2, 97.9, 97.8, 98.0, 98.2),
                             Tuple.Create(1, 98.6, 98.8, 98.8, 99.0), 
                             Tuple.Create(2, 98.6, 98.6, 98.6, 98.4),
                             Tuple.Create(1, 98.4, 98.6, 99.0, 99.2),
                             Tuple.Create(2, 98.6, 98.6, 98.6, 98.4),
                             Tuple.Create(1, 98.6, 98.8, 98.8, 99.0) }; 
      // Compare each item with every other item for equality.
      for (int ctr = 0; ctr < temperatureInfos.Length; ctr++)
      {
         var temperatureInfo = temperatureInfos[ctr];
         for (int ctr2 = ctr + 1; ctr2 < temperatureInfos.Length; ctr2++)
            Console.WriteLine("{0} = {1}: {2}", temperatureInfo, temperatureInfos[ctr2], 
                                                temperatureInfo.Equals(temperatureInfos[ctr2]));
         Console.WriteLine();
      }   
   }
}
// The example displays the following output:
//    (2, 97.9, 97.8, 98, 98.2) = (1, 98.6, 98.8, 98.8, 99): False
//    (2, 97.9, 97.8, 98, 98.2) = (2, 98.6, 98.6, 98.6, 98.4): False
//    (2, 97.9, 97.8, 98, 98.2) = (1, 98.4, 98.6, 99, 99.2): False
//    (2, 97.9, 97.8, 98, 98.2) = (2, 98.6, 98.6, 98.6, 98.4): False
//    (2, 97.9, 97.8, 98, 98.2) = (1, 98.6, 98.8, 98.8, 99): False
//    
//    (1, 98.6, 98.8, 98.8, 99) = (2, 98.6, 98.6, 98.6, 98.4): False
//    (1, 98.6, 98.8, 98.8, 99) = (1, 98.4, 98.6, 99, 99.2): False
//    (1, 98.6, 98.8, 98.8, 99) = (2, 98.6, 98.6, 98.6, 98.4): False
//    (1, 98.6, 98.8, 98.8, 99) = (1, 98.6, 98.8, 98.8, 99): True
//    
//    (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.4, 98.6, 99, 99.2): False
//    (2, 98.6, 98.6, 98.6, 98.4) = (2, 98.6, 98.6, 98.6, 98.4): True
//    (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.6, 98.8, 98.8, 99): False
//    
//    (1, 98.4, 98.6, 99, 99.2) = (2, 98.6, 98.6, 98.6, 98.4): False
//    (1, 98.4, 98.6, 99, 99.2) = (1, 98.6, 98.8, 98.8, 99): False
//    
//    (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.6, 98.8, 98.8, 99): False
open System

let temperatureInfos = 
    [| Tuple.Create(2, 97.9, 97.8, 98.0, 98.2)
       Tuple.Create(1, 98.6, 98.8, 98.8, 99.0)
       Tuple.Create(2, 98.6, 98.6, 98.6, 98.4)
       Tuple.Create(1, 98.4, 98.6, 99.0, 99.2)
       Tuple.Create(2, 98.6, 98.6, 98.6, 98.4)
       Tuple.Create(1, 98.6, 98.8, 98.8, 99.0) |]
// Compare each item with every other item for equality.
for ctr = 0 to temperatureInfos.Length - 1 do
    let temperatureInfo = temperatureInfos[ctr]
    for ctr2 = ctr + 1 to temperatureInfos.Length - 1 do
        printfn $"{temperatureInfo} = {temperatureInfos[ctr2]}: {temperatureInfo.Equals temperatureInfos[ctr2]}"
    printfn ""

// The example displays the following output:
//    (2, 97.9, 97.8, 98, 98.2) = (1, 98.6, 98.8, 98.8, 99): False
//    (2, 97.9, 97.8, 98, 98.2) = (2, 98.6, 98.6, 98.6, 98.4): False
//    (2, 97.9, 97.8, 98, 98.2) = (1, 98.4, 98.6, 99, 99.2): False
//    (2, 97.9, 97.8, 98, 98.2) = (2, 98.6, 98.6, 98.6, 98.4): False
//    (2, 97.9, 97.8, 98, 98.2) = (1, 98.6, 98.8, 98.8, 99): False
//    
//    (1, 98.6, 98.8, 98.8, 99) = (2, 98.6, 98.6, 98.6, 98.4): False
//    (1, 98.6, 98.8, 98.8, 99) = (1, 98.4, 98.6, 99, 99.2): False
//    (1, 98.6, 98.8, 98.8, 99) = (2, 98.6, 98.6, 98.6, 98.4): False
//    (1, 98.6, 98.8, 98.8, 99) = (1, 98.6, 98.8, 98.8, 99): True
//    
//    (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.4, 98.6, 99, 99.2): False
//    (2, 98.6, 98.6, 98.6, 98.4) = (2, 98.6, 98.6, 98.6, 98.4): True
//    (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.6, 98.8, 98.8, 99): False
//    
//    (1, 98.4, 98.6, 99, 99.2) = (2, 98.6, 98.6, 98.6, 98.4): False
//    (1, 98.4, 98.6, 99, 99.2) = (1, 98.6, 98.8, 98.8, 99): False
//    
//    (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.6, 98.8, 98.8, 99): False
Module Example
   Public Sub Main()
      Dim temperatureInfos() = 
             { Tuple.Create(2, 97.9, 97.8, 98.0, 98.2), 
               Tuple.Create(1, 98.6, 98.8, 98.8, 99.0),  
               Tuple.Create(2, 98.6, 98.6, 98.6, 98.4), 
               Tuple.Create(1, 98.4, 98.6, 99.0, 99.2), 
               Tuple.Create(2, 98.6, 98.6, 98.6, 98.4), 
               Tuple.Create(1, 98.6, 98.8, 98.8, 99.0) } 
      ' Compare each item with every other item for equality.
      For ctr As Integer = 0 To temperatureInfos.Length - 1
         Dim temperatureInfo = temperatureInfos(ctr)
         For ctr2 As Integer = ctr + 1 To temperatureInfos.Length - 1
            Console.WriteLine("{0} = {1}: {2}", temperatureInfo, temperatureInfos(ctr2), 
                                                temperatureInfo.Equals(temperatureInfos(ctr2)))
         Next  
         Console.WriteLine()                                               
      Next
   End Sub
End Module
' The example displays the following output:
'    (2, 97.9, 97.8, 98, 98.2) = (1, 98.6, 98.8, 98.8, 99): False
'    (2, 97.9, 97.8, 98, 98.2) = (2, 98.6, 98.6, 98.6, 98.4): False
'    (2, 97.9, 97.8, 98, 98.2) = (1, 98.4, 98.6, 99, 99.2): False
'    (2, 97.9, 97.8, 98, 98.2) = (2, 98.6, 98.6, 98.6, 98.4): False
'    (2, 97.9, 97.8, 98, 98.2) = (1, 98.6, 98.8, 98.8, 99): False
'    
'    (1, 98.6, 98.8, 98.8, 99) = (2, 98.6, 98.6, 98.6, 98.4): False
'    (1, 98.6, 98.8, 98.8, 99) = (1, 98.4, 98.6, 99, 99.2): False
'    (1, 98.6, 98.8, 98.8, 99) = (2, 98.6, 98.6, 98.6, 98.4): False
'    (1, 98.6, 98.8, 98.8, 99) = (1, 98.6, 98.8, 98.8, 99): True
'    
'    (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.4, 98.6, 99, 99.2): False
'    (2, 98.6, 98.6, 98.6, 98.4) = (2, 98.6, 98.6, 98.6, 98.4): True
'    (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.6, 98.8, 98.8, 99): False
'    
'    (1, 98.4, 98.6, 99, 99.2) = (2, 98.6, 98.6, 98.6, 98.4): False
'    (1, 98.4, 98.6, 99, 99.2) = (1, 98.6, 98.8, 98.8, 99): False
'    
'    (2, 98.6, 98.6, 98.6, 98.4) = (1, 98.6, 98.8, 98.8, 99): False

Commenti

Il obj parametro viene considerato uguale all'istanza corrente nelle condizioni seguenti:

  • Si tratta di un Tuple<T1,T2,T3,T4,T5> oggetto .

  • I cinque componenti sono degli stessi tipi dell'istanza corrente.

  • I suoi cinque componenti sono uguali a quelli dell'istanza corrente. L'uguaglianza è determinata dall'operatore di uguaglianza predefinito dell'oggetto per ogni componente.

Si applica a