Tuple<T1,T2,T3,T4,T5>.Equals(Object) Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Retorna um valor que indica se o objeto Tuple<T1,T2,T3,T4,T5> atual é igual a um objeto especificado.
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
Parâmetros
- obj
- Object
O objeto a ser comparado com essa instância.
Retornos
true
caso a instância atual seja igual ao objeto especificado; do contrário, false
.
Exemplos
O exemplo a seguir define uma matriz de objetos de cinco tuplas que contêm dados sobre as temperaturas dos pacientes em dois grupos de teste. O primeiro componente da matriz fornece o número do grupo de teste e o segundo ao quinto componentes fornecem as temperaturas de um paciente em intervalos de hora em hora. O Tuple<T1,T2,T3,T4,T5>.Equals(Object) método é chamado para comparar todos os Tuple<T1,T2,T3,T4,T5> objetos com todos os outros Tuple<T1,T2,T3,T4,T5> objetos. A saída ilustra que o Equals método retorna true
somente quando todos os cinco componentes dos Tuple<T1,T2,T3,T4,T5> objetos têm valores iguais.
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
Comentários
O parâmetro obj
deve ser considerado igual à instância atual nas seguintes circunstâncias:
É um Tuple<T1,T2,T3,T4,T5> objeto .
Seus cinco componentes são dos mesmos tipos que a instância atual.
Seus cinco componentes são iguais aos da instância atual. A igualdade é determinada pela comparação de igualdade do objeto padrão para cada componente.