共用方式為


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

定義

傳回值,這個值表示目前的 Tuple<T1,T2,T3,T4> 物件是否等於指定的物件。

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

與這個執行個體相互比較的物件。

傳回

Boolean

如果目前的執行個體和指定的物件相等,則為 true,否則為 false

範例

下列範例會定義 物件的陣列,該陣列 Tuple<T1,T2,T3,T4> 會在特定一天提供溫度三次的資料。 系統會 Equals(Object) 呼叫 方法,以比較每個 Tuple<T1,T2,T3,T4> 物件與其他 Tuple<T1,T2,T3,T4> 物件。 輸出說明 Equals(Object) 只有在物件的所有四個元件 Tuple<T1,T2,T3,T4> 都有相等值時,方法才會傳回 true

using System;

public class Class1
{
   public static void Main()
   {
      Tuple<DateTime, double, double, double>[] temperatures = 
            { Tuple.Create(new DateTime(2009, 1, 16), 3.0, 5.0, 4.0),
              Tuple.Create(new DateTime(2009, 4, 22), 9.0, 14.0, 11.0), 
              Tuple.Create(new DateTime(2009, 4, 22), 9.0, 14.0, 10.0),
              Tuple.Create(new DateTime(2009, 6, 1), 23.0, 28.0, 21.0),
              Tuple.Create(new DateTime(2009, 4, 22), 9.0, 14.0, 11.0),
              Tuple.Create(new DateTime(2009, 9, 6), 25.0, 30.0, 25.0) }; 
      // Compare each item with every other item for equality.
      for (int ctr = 0; ctr < temperatures.Length; ctr++)
      {
         var temperatureInfo = temperatures[ctr];
         for (int ctr2 = ctr + 1; ctr2 < temperatures.Length; ctr2++)
            Console.WriteLine("{0} = {1}: {2}", temperatureInfo, temperatures[ctr2], 
                                                temperatureInfo.Equals(temperatures[ctr2]));
         Console.WriteLine();
      }   
   }
}
// The example displays the following output:
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 10): False
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
//    
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (4/22/2009 12:00:00 AM, 9, 14, 10): False
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (4/22/2009 12:00:00 AM, 9, 14, 11): True
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
//    
//    (4/22/2009 12:00:00 AM, 9, 14, 10) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
//    (4/22/2009 12:00:00 AM, 9, 14, 10) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
//    (4/22/2009 12:00:00 AM, 9, 14, 10) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
//    
//    (6/1/2009 12:00:00 AM, 23, 28, 21) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
//    (6/1/2009 12:00:00 AM, 23, 28, 21) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
//    
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
open System

let temperatures = 
    [| Tuple.Create(DateTime(2009, 1, 16), 3.0, 5.0, 4.0)
       Tuple.Create(DateTime(2009, 4, 22), 9.0, 14.0, 11.0)
       Tuple.Create(DateTime(2009, 4, 22), 9.0, 14.0, 10.0)
       Tuple.Create(DateTime(2009, 6, 1), 23.0, 28.0, 21.0)
       Tuple.Create(DateTime(2009, 4, 22), 9.0, 14.0, 11.0)
       Tuple.Create(DateTime(2009, 9, 6), 25.0, 30.0, 25.0) |]

// Compare each item with every other item for equality.
for ctr = 0 to temperatures.Length - 1 do
    let temperatureInfo = temperatures[ctr]
    for ctr2 = ctr + 1 to temperatures.Length - 1 do
        printfn $"{temperatureInfo} = {temperatures[ctr2]}: {temperatureInfo.Equals temperatures[ctr2]}"
    printfn ""   
// The example displays the following output:
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 10): False
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
//    
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (4/22/2009 12:00:00 AM, 9, 14, 10): False
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (4/22/2009 12:00:00 AM, 9, 14, 11): True
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
//    
//    (4/22/2009 12:00:00 AM, 9, 14, 10) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
//    (4/22/2009 12:00:00 AM, 9, 14, 10) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
//    (4/22/2009 12:00:00 AM, 9, 14, 10) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
//    
//    (6/1/2009 12:00:00 AM, 23, 28, 21) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
//    (6/1/2009 12:00:00 AM, 23, 28, 21) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
//    
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
Module Example
   Public Sub Main()
      Dim temperatures() = 
              { Tuple.Create(#1/16/2009#, 3, 5, 4), _
                Tuple.Create(#4/22/2009#, 9, 14, 11), _ 
                Tuple.Create(#4/22/2009#, 9, 14, 10), _
                Tuple.Create(#6/01/2009#, 23, 28, 21), _
                Tuple.Create(#4/22/2009#, 9, 14, 11), _
                Tuple.Create(#9/06/2009#, 25, 30, 25) } 
      ' Compare each item with every other item for equality.
      For ctr As Integer = 0 To temperatures.Length - 1
         Dim temperatureInfo = temperatures(ctr)
         For ctr2 As Integer = ctr + 1 To temperatures.Length - 1
            Console.WriteLine("{0} = {1}: {2}", temperatureInfo, temperatures(ctr2), 
                                                temperatureInfo.Equals(temperatures(ctr2)))
         Next  
         Console.WriteLine()                                               
      Next
   End Sub
End Module
' The example displays the following output:
'    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
'    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 10): False
'    (1/16/2009 12:00:00 AM, 3, 5, 4) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
'    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
'    (1/16/2009 12:00:00 AM, 3, 5, 4) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
'    
'    (4/22/2009 12:00:00 AM, 9, 14, 11) = (4/22/2009 12:00:00 AM, 9, 14, 10): False
'    (4/22/2009 12:00:00 AM, 9, 14, 11) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
'    (4/22/2009 12:00:00 AM, 9, 14, 11) = (4/22/2009 12:00:00 AM, 9, 14, 11): True
'    (4/22/2009 12:00:00 AM, 9, 14, 11) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
'    
'    (4/22/2009 12:00:00 AM, 9, 14, 10) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
'    (4/22/2009 12:00:00 AM, 9, 14, 10) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
'    (4/22/2009 12:00:00 AM, 9, 14, 10) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
'    
'    (6/1/2009 12:00:00 AM, 23, 28, 21) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
'    (6/1/2009 12:00:00 AM, 23, 28, 21) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
'    
'    (4/22/2009 12:00:00 AM, 9, 14, 11) = (9/6/2009 12:00:00 AM, 25, 30, 25): False

備註

參數 obj 在下列情況下會被視為等於目前的實例:

  • Tuple<T1,T2,T3,T4>它是 物件。

  • 其四個元件的類型與目前的實例相同。

  • 其四個元件等於目前實例的元件。 是否相等由每個元件的預設物件相等比較子決定。

適用於