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

定义

返回一个值,该值指示当前的 Tuple<T1,T2,T3,T4,T5> 对象是否与指定对象相等。

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

示例

以下示例定义一个包含 5 元组对象的数组,这些对象包含有关两个测试组中患者温度的数据。 数组的第一个组件提供测试组的数量,第二个到第五个组件按小时间隔提供患者的温度。 Tuple<T1,T2,T3,T4,T5>.Equals(Object)调用 方法以将每个对象与其他Tuple<T1,T2,T3,T4,T5>每个Tuple<T1,T2,T3,T4,T5>对象进行比较。 输出说明Equals仅当对象的所有五个Tuple<T1,T2,T3,T4,T5>组件都具有相等值时, 方法才返回 true

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

注解

obj 以下条件下, 参数被视为等于当前实例:

  • 它是一个 Tuple<T1,T2,T3,T4,T5> 对象。

  • 其五个组件的类型与当前实例的类型相同。

  • 其五个组件等于当前实例的组件。 相等性取决于每个组件的默认对象相等比较器。

适用于