共用方式為


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

定義

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

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,T5,T6,T7,TRest> 個 物件。 然後,它會比較第一個物件與每個剩餘的物件。 如輸出所示,只有第一個和最後 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 一個物件相等,因為它們具有相同值的元件數目相同。

using System;

public class Class1
{
   public static void Main()
   {
      // Create five 8-tuple objects containing prime numbers.
      var prime1 = new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
                           Tuple<Int32>> (2, 3, 5, 7, 11, 13, 17, 
                           new Tuple<Int32>(19));
      var prime2 = new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
                           Tuple<Int32>> (23, 29, 31, 37, 41, 43, 47, 
                           new Tuple<Int32>(55));
      var prime3 = new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
                           Tuple<Int32>> (3, 2, 5, 7, 11, 13, 17, 
                           new Tuple<Int32>(19)); 
      var prime4 = new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
                           Tuple<Int32, Int32>> (2, 3, 5, 7, 11, 13, 17, 
                           new Tuple<Int32, Int32>(19, 23));
      var prime5 = new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
                           Tuple<Int32>> (2, 3, 5, 7, 11, 13, 17, 
                           new Tuple<Int32>(19));
      Console.WriteLine("{0} = {1} : {2}", prime1, prime2, prime1.Equals(prime2));
      Console.WriteLine("{0} = {1} : {2}", prime1, prime3, prime1.Equals(prime3));
      Console.WriteLine("{0} = {1} : {2}", prime1, prime4, prime1.Equals(prime4));
      Console.WriteLine("{0} = {1} : {2}", prime1, prime5, prime1.Equals(prime5));
   }
}
// The example displays the following output:
//    (2, 3, 5, 7, 11, 13, 17, 19) = (23, 29, 31, 37, 41, 43, 47, 55) : False
//    (2, 3, 5, 7, 11, 13, 17, 19) = (3, 2, 5, 7, 11, 13, 17, 19) : False
//    (2, 3, 5, 7, 11, 13, 17, 19) = (2, 3, 5, 7, 11, 13, 17, 19, 23) : False
//    (2, 3, 5, 7, 11, 13, 17, 19) = (2, 3, 5, 7, 11, 13, 17, 19) : True
open System

// Create five 8-tuple objects containing prime numbers.
let prime1 = 
    new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
        Tuple<Int32>> (2, 3, 5, 7, 11, 13, 17, 
        new Tuple<Int32>(19))
let prime2 = 
    new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
        Tuple<Int32>> (23, 29, 31, 37, 41, 43, 47, 
        new Tuple<Int32>(55))
let prime3 = 
    new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
        Tuple<Int32>> (3, 2, 5, 7, 11, 13, 17, 
        new Tuple<Int32>(19)) 
let prime4 = 
    new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
        Tuple<Int32, Int32>> (2, 3, 5, 7, 11, 13, 17, 
        new Tuple<Int32, Int32>(19, 23))
let prime5 = 
    new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
        Tuple<Int32>> (2, 3, 5, 7, 11, 13, 17, 
        new Tuple<Int32>(19))
printfn $"{prime1} = {prime2} : {prime1.Equals prime2}"
printfn $"{prime1} = {prime3} : {prime1.Equals prime3}"
printfn $"{prime1} = {prime4} : {prime1.Equals prime4}"
printfn $"{prime1} = {prime5} : {prime1.Equals prime5}"
// The example displays the following output:
//    (2, 3, 5, 7, 11, 13, 17, 19) = (23, 29, 31, 37, 41, 43, 47, 55) : False
//    (2, 3, 5, 7, 11, 13, 17, 19) = (3, 2, 5, 7, 11, 13, 17, 19) : False
//    (2, 3, 5, 7, 11, 13, 17, 19) = (2, 3, 5, 7, 11, 13, 17, 19, 23) : False
//    (2, 3, 5, 7, 11, 13, 17, 19) = (2, 3, 5, 7, 11, 13, 17, 19) : True
Module Example
   Public Sub Main()
      ' Create five 8-tuple objects containing prime numbers.
      Dim prime1 = New Tuple(Of Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
                           Tuple(Of Int32)) (2, 3, 5, 7, 11, 13, 17, 
                           New Tuple(Of Int32)(19))
      Dim prime2 = New Tuple(Of Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
                           Tuple(Of Int32)) (23, 29, 31, 37, 41, 43, 47, 
                           New Tuple(Of Int32)(55)) 
      Dim prime3 = New Tuple(Of Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
                           Tuple(Of Int32)) (3, 2, 5, 7, 11, 13, 17, 
                           New Tuple(Of Int32)(19)) 
      Dim prime4 = New Tuple(Of Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
                           Tuple(Of Int32, Int32)) (2, 3, 5, 7, 11, 13, 17, 
                           New Tuple(Of Int32, Int32)(19, 23))
      Dim prime5 = New Tuple(Of Int32, Int32, Int32, Int32, Int32, Int32, Int32, 
                           Tuple(Of Int32)) (2, 3, 5, 7, 11, 13, 17, 
                           New Tuple(Of Int32)(19))
      Console.WriteLine("{0} = {1} : {2}", prime1, prime2, prime1.Equals(prime2))
      Console.WriteLine("{0} = {1} : {2}", prime1, prime3, prime1.Equals(prime3))
      Console.WriteLine("{0} = {1} : {2}", prime1, prime4, prime1.Equals(prime4))
      Console.WriteLine("{0} = {1} : {2}", prime1, prime5, prime1.Equals(prime5))
   End Sub
End Module
' The example displays the following output:
'    (2, 3, 5, 7, 11, 13, 17, 19) = (23, 29, 31, 37, 41, 43, 47, 55) : False
'    (2, 3, 5, 7, 11, 13, 17, 19) = (3, 2, 5, 7, 11, 13, 17, 19) : False
'    (2, 3, 5, 7, 11, 13, 17, 19) = (2, 3, 5, 7, 11, 13, 17, 19, 23) : False
'    (2, 3, 5, 7, 11, 13, 17, 19) = (2, 3, 5, 7, 11, 13, 17, 19) : True

備註

如果參數符合下列所有條件,則 obj 參數會被視為等於目前的實例:

  • Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>它是 物件。

  • 其元件總數與目前實例的類型相同。

  • 其元件 (包括其巢狀元件,) 等於目前實例的元件。 相等是由每個元件的預設相等比較子所決定。

適用於