Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Tuple<T1, T2, T3>.Equals Method

Returns a value that indicates whether the current Tuple<T1, T2, T3> 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> object.

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

  • Its three components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component.

The following example calls the Tuple<T1, T2, T3>.Equals(Object) method to determine whether any of the objects in an array of Tuple<T1, T2, T3> objects are equal to one another. The output reflects the fact that the Equals(Object) method returns true when comparing Tuple<T1, T2, T3> objects whose components have equal values.

using System;

public class Example
{
   public static void Main()
   {
      Tuple<string, double, int>[] scores = 
                      { Tuple.Create("Ed", 78.8, 8),
                        Tuple.Create("Abbey", 92.1, 9), 
                        Tuple.Create("Ed", 71.2, 9),
                        Tuple.Create("Sam", 91.7, 8), 
                        Tuple.Create("Ed", 71.2, 5),
                        Tuple.Create("Penelope", 82.9, 8),
                        Tuple.Create("Ed", 71.2, 9),
                        Tuple.Create("Judith", 84.3, 9) };

      // Test each tuple object for equality with every other tuple. 
      for (int ctr = 0; ctr < scores.Length; ctr++)
      {
         var currentTuple = scores[ctr];
         for (int ctr2 = ctr + 1; ctr2 < scores.Length; ctr2++)
            Console.WriteLine("{0} = {1}: {2}", currentTuple, scores[ctr2], 
                                                currentTuple.Equals(scores[ctr2]));      

         Console.WriteLine();
      }   
   }
}
// The example displays the following output; 
//    (Ed, 78.8, 8) = (Abbey, 92.1, 9): False 
//    (Ed, 78.8, 8) = (Ed, 71.2, 9): False 
//    (Ed, 78.8, 8) = (Sam, 91.7, 8): False 
//    (Ed, 78.8, 8) = (Ed, 71.2, 5): False 
//    (Ed, 78.8, 8) = (Penelope, 82.9, 8): False 
//    (Ed, 78.8, 8) = (Ed, 71.2, 9): False 
//    (Ed, 78.8, 8) = (Judith, 84.3, 9): False 
//     
//    (Abbey, 92.1, 9) = (Ed, 71.2, 9): False 
//    (Abbey, 92.1, 9) = (Sam, 91.7, 8): False 
//    (Abbey, 92.1, 9) = (Ed, 71.2, 5): False 
//    (Abbey, 92.1, 9) = (Penelope, 82.9, 8): False 
//    (Abbey, 92.1, 9) = (Ed, 71.2, 9): False 
//    (Abbey, 92.1, 9) = (Judith, 84.3, 9): False 
//     
//    (Ed, 71.2, 9) = (Sam, 91.7, 8): False 
//    (Ed, 71.2, 9) = (Ed, 71.2, 5): False 
//    (Ed, 71.2, 9) = (Penelope, 82.9, 8): False 
//    (Ed, 71.2, 9) = (Ed, 71.2, 9): True 
//    (Ed, 71.2, 9) = (Judith, 84.3, 9): False 
//     
//    (Sam, 91.7, 8) = (Ed, 71.2, 5): False 
//    (Sam, 91.7, 8) = (Penelope, 82.9, 8): False 
//    (Sam, 91.7, 8) = (Ed, 71.2, 9): False 
//    (Sam, 91.7, 8) = (Judith, 84.3, 9): False 
//     
//    (Ed, 71.2, 5) = (Penelope, 82.9, 8): False 
//    (Ed, 71.2, 5) = (Ed, 71.2, 9): False 
//    (Ed, 71.2, 5) = (Judith, 84.3, 9): False 
//     
//    (Penelope, 82.9, 8) = (Ed, 71.2, 9): False 
//    (Penelope, 82.9, 8) = (Judith, 84.3, 9): False 
//     
//    (Ed, 71.2, 9) = (Judith, 84.3, 9): False

.NET Framework

Supported in: 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.