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

定义

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

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

示例

以下示例定义了一个包含 1950 年到 2000 年洛杉矶和纽约的人口数据的性别对象数组。 每个隔开区的第一个组件标识城市。 第一、第三和第四个九月包含纽约的数据。 第一个九月是第四个九月的重复。 第三个九点将城市标识为“纽约市”,而不是“纽约”。 如示例所示,只有第四个隔点等于第一个隔点。

using System;

public class Example
{
   public static void Main()
   {
      // Get population data for New York City and Los Angeles, 1960-2000.
      Tuple<string, int, int, int, int, int, int>[] urbanPopulations =
           { Tuple.Create("New York", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278),
             Tuple.Create("Los Angeles", 1970358, 2479015, 2816061, 2966850, 3485398, 3694820),
             Tuple.Create("New York City", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278),
             Tuple.Create("New York", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) };
      // Compare each tuple with every other tuple for equality.
      for (int ctr = 0; ctr <= urbanPopulations.Length - 2; ctr++)
      {                      
         var urbanPopulation = urbanPopulations[ctr];
         Console.WriteLine(urbanPopulation.ToString() + " = ");
         for (int innerCtr = ctr +1; innerCtr <= urbanPopulations.Length - 1; innerCtr++)
            Console.WriteLine("   {0}: {1}", urbanPopulations[innerCtr], 
                              urbanPopulation.Equals(urbanPopulations[innerCtr]));
         Console.WriteLine();
      }   
   }
}
// The example displays the following output:
//    (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) =
//       (Los Angeles, 1970358, 2479015, 2816061, 2966850, 3485398, 3694820): False
//       (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
//       (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): True
//    
//    (Los Angeles, 1970358, 2479015, 2816061, 2966850, 3485398, 3694820) =
//       (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
//       (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
//    
//    (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) =
//       (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
open System

// Get population data for New York City and Los Angeles, 1960-2000.
let urbanPopulations =
    [| Tuple.Create("New York", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278)
       Tuple.Create("Los Angeles", 1970358, 2479015, 2816061, 2966850, 3485398, 3694820)
       Tuple.Create("New York City", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278)
       Tuple.Create("New York", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) |]
// Compare each tuple with every other tuple for equality.
for ctr = 0 to urbanPopulations.Length - 2 do
    let urbanPopulation = urbanPopulations[ctr]
    printfn $"{urbanPopulation} = "
    for innerCtr = ctr + 1 to urbanPopulations.Length - 1 do
        printfn $"   {urbanPopulations[innerCtr]}: {urbanPopulation.Equals urbanPopulations[innerCtr]}"
    printfn ""
// The example displays the following output:
//    (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) =
//       (Los Angeles, 1970358, 2479015, 2816061, 2966850, 3485398, 3694820): False
//       (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
//       (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): True
//    
//    (Los Angeles, 1970358, 2479015, 2816061, 2966850, 3485398, 3694820) =
//       (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
//       (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
//    
//    (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) =
//       (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
Module Example
   Public Sub Main()
      ' Get population data for New York City and Los Angeles, 1960-2000.
      Dim urbanPopulations() =
           { Tuple.Create("New York", 7891957, 7781984, 7894862, 
                          7071639, 7322564, 8008278),
             Tuple.Create("Los Angeles", 1970358, 2479015, 2816061, 
                          2966850, 3485398, 3694820),
             Tuple.Create("New York City", 7891957, 7781984, 7894862, 
                          7071639, 7322564, 8008278),
             Tuple.Create("New York", 7891957, 7781984, 7894862, 
                          7071639, 7322564, 8008278) }
      ' Compare each tuple with every other tuple for equality.
      For ctr As Integer = 0 To urbanPopulations.Length - 2                      
         Dim urbanPopulation = urbanPopulations(ctr)
         Console.WriteLine(urbanPopulation.ToString() + " = ")
         For innerCtr As Integer = ctr + 1 To urbanPopulations.Length - 1
            Console.WriteLine("   {0}: {1}", urbanPopulations(innerCtr), _
                              urbanPopulation.Equals(urbanPopulations(innerCtr)))
         Next
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output:
'    (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) =
'       (Los Angeles, 1970358, 2479015, 2816061, 2966850, 3485398, 3694820): False
'       (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
'       (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): True
'    
'    (Los Angeles, 1970358, 2479015, 2816061, 2966850, 3485398, 3694820) =
'       (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
'       (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False
'    
'    (New York City, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278) =
'       (New York, 7891957, 7781984, 7894862, 7071639, 7322564, 8008278): False

注解

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

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

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

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

适用于