Export (0) Print
Expand All

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

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)

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.

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.

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.


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


Silverlight

Supported in: 5, 4

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

Community Additions

ADD
Show:
© 2014 Microsoft