Поделиться через


Tuple<T1, T2, T3, T4, T5, T6>.Equals Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Returns a value that indicates whether the current Tuple<T1, T2, T3, T4, T5, T6> object is equal to a specified object.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Overrides Function Equals ( _
    obj As Object _
) As Boolean
public override bool Equals(
    Object obj
)

Parameters

  • obj
    Type: System.Object
    The object to compare with this instance.

Return Value

Type: System.Boolean
true if the current instance is equal to the specified object; otherwise, false.

Remarks

The obj parameter is considered to be equal to the current instance under the following conditions:

  • It is a Tuple<T1, T2, T3, T4, T5, T6> object.

  • Its six components are of the same types as the current instance.

  • Its six components have the same values as those of the current instance.

Examples

The following example defines an array of sextuples that contain population data for Los Angeles and New York from 1960 to 2000. The first component of each sextuple identifies the city. The first, third, and fourth sextuples contain data for New York. The first sextuple is a duplicate of the fourth sextuple. The third sextuple identifies the city as "New York City" instead of "New York". As the example shows, only the fourth sextuple is equal to the first sextuple.

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      ' Get population data for New York City and Los Angeles, 1960-2000.
      Dim urbanPopulations() = _
           { Tuple.Create("New York", 7781984, 7894862, _ 
                          7071639, 7322564, 8008278), _
             Tuple.Create("Los Angeles", 2479015, 2816061, _ 
                          2966850, 3485398, 3694820), _
             Tuple.Create("New York City", 7781984, 7894862, _ 
                          7071639, 7322564, 8008278), _
             Tuple.Create("New York", 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)
         outputBlock.Text &= urbanPopulation.ToString() + " = " & vbCrLf
         For innerCtr As Integer = ctr + 1 To urbanPopulations.Length - 1
            outputBlock.Text += String.Format("   {0}: {1}", urbanPopulations(innerCtr), _
                              urbanPopulation.Equals(urbanPopulations(innerCtr))) + vbCrLf
         Next
         outputBlock.Text &= vbCrLf
      Next
   End Sub
End Module
' The example displays the following output:
'    (New York, 7781984, 7894862, 7071639, 7322564, 8008278) =
'       (Los Angeles, 2479015, 2816061, 2966850, 3485398, 3694820): False
'       (New York City, 7781984, 7894862, 7071639, 7322564, 8008278): False
'       (New York, 7781984, 7894862, 7071639, 7322564, 8008278): True
'    
'    (Los Angeles, 2479015, 2816061, 2966850, 3485398, 3694820) =
'       (New York City, 7781984, 7894862, 7071639, 7322564, 8008278): False
'       (New York, 7781984, 7894862, 7071639, 7322564, 8008278): False
'    
'    (New York City, 7781984, 7894862, 7071639, 7322564, 8008278) =
'       (New York, 7781984, 7894862, 7071639, 7322564, 8008278): False
using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Get population data for New York City and Los Angeles, 1960-2000.
      Tuple<string, int, int, int, int, int>[] urbanPopulations =
           { Tuple.Create("New York", 7781984, 7894862, 7071639, 7322564, 8008278),
             Tuple.Create("Los Angeles", 2479015, 2816061, 2966850, 3485398, 3694820),
             Tuple.Create("New York City", 7781984, 7894862, 7071639, 7322564, 8008278),
             Tuple.Create("New York", 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];
         outputBlock.Text += urbanPopulation.ToString() + " = " + "\n";
         for (int innerCtr = ctr + 1; innerCtr <= urbanPopulations.Length - 1; innerCtr++)
            outputBlock.Text += String.Format("   {0}: {1}", urbanPopulations[innerCtr],
                              urbanPopulation.Equals(urbanPopulations[innerCtr])) + "\n";
         outputBlock.Text += "\n";
      }
   }
}
// The example displays the following output:
//    (New York, 7781984, 7894862, 7071639, 7322564, 8008278) =
//       (Los Angeles, 2479015, 2816061, 2966850, 3485398, 3694820): False
//       (New York City, 7781984, 7894862, 7071639, 7322564, 8008278): False
//       (New York, 7781984, 7894862, 7071639, 7322564, 8008278): True
//    
//    (Los Angeles, 2479015, 2816061, 2966850, 3485398, 3694820) =
//       (New York City, 7781984, 7894862, 7071639, 7322564, 8008278): False
//       (New York, 7781984, 7894862, 7071639, 7322564, 8008278): False
//    
//    (New York City, 7781984, 7894862, 7071639, 7322564, 8008278) =
//       (New York, 7781984, 7894862, 7071639, 7322564, 8008278): False

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.