Tuple<T1, T2, T3, T4>.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> 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> object.

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

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

Examples

The following example defines an array of Tuple<T1, T2, T3, T4> objects that provide data on temperatures at three times during a particular day. The Equals(Object) method is called to compare every Tuple<T1, T2, T3, T4> object with every other Tuple<T1, T2, T3, T4> object. The output illustrates that the Equals(Object) method returns true only when all four components of the Tuple<T1, T2, T3, T4> objects have equal values.

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim temperatures() = _ 
              { Tuple.Create(#1/16/2009#, 3, 5, 4), _
                Tuple.Create(#4/22/2009#, 9, 14, 11), _ 
                Tuple.Create(#4/22/2009#, 9, 14, 10), _
                Tuple.Create(#6/01/2009#, 23, 28, 21), _
                Tuple.Create(#4/22/2009#, 9, 14, 11), _
                Tuple.Create(#9/06/2009#, 25, 30, 25) } 
      ' Compare each item with every other item for equality.
      For ctr As Integer = 0 To temperatures.Length - 1
         Dim temperatureInfo = temperatures(ctr)
         For ctr2 As Integer = ctr + 1 To temperatures.Length - 1
            outputBlock.Text += String.Format("{0} = {1}: {2}", temperatureInfo, temperatures(ctr2), _ 
                                                temperatureInfo.Equals(temperatures(ctr2))) + vbCrLf
         Next
         outputBlock.Text &= vbCrLf
      Next
   End Sub
End Module
' The example displays the following output:
'    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
'    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 10): False
'    (1/16/2009 12:00:00 AM, 3, 5, 4) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
'    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
'    (1/16/2009 12:00:00 AM, 3, 5, 4) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
'    
'    (4/22/2009 12:00:00 AM, 9, 14, 11) = (4/22/2009 12:00:00 AM, 9, 14, 10): False
'    (4/22/2009 12:00:00 AM, 9, 14, 11) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
'    (4/22/2009 12:00:00 AM, 9, 14, 11) = (4/22/2009 12:00:00 AM, 9, 14, 11): True
'    (4/22/2009 12:00:00 AM, 9, 14, 11) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
'    
'    (4/22/2009 12:00:00 AM, 9, 14, 10) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
'    (4/22/2009 12:00:00 AM, 9, 14, 10) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
'    (4/22/2009 12:00:00 AM, 9, 14, 10) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
'    
'    (6/1/2009 12:00:00 AM, 23, 28, 21) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
'    (6/1/2009 12:00:00 AM, 23, 28, 21) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
'    
'    (4/22/2009 12:00:00 AM, 9, 14, 11) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      Tuple<DateTime, double, double, double>[] temperatures = 
            { Tuple.Create(new DateTime(2009, 1, 16), 3.0, 5.0, 4.0),
              Tuple.Create(new DateTime(2009, 4, 22), 9.0, 14.0, 11.0), 
              Tuple.Create(new DateTime(2009, 4, 22), 9.0, 14.0, 10.0),
              Tuple.Create(new DateTime(2009, 6, 1), 23.0, 28.0, 21.0),
              Tuple.Create(new DateTime(2009, 4, 22), 9.0, 14.0, 11.0),
              Tuple.Create(new DateTime(2009, 9, 6), 25.0, 30.0, 25.0) };
      // Compare each item with every other item for equality.
      for (int ctr = 0; ctr < temperatures.Length; ctr++)
      {
         var temperatureInfo = temperatures[ctr];
         for (int ctr2 = ctr + 1; ctr2 < temperatures.Length; ctr2++)
            outputBlock.Text += String.Format("{0} = {1}: {2}", temperatureInfo, temperatures[ctr2],
                                                temperatureInfo.Equals(temperatures[ctr2])) + "\n";
         outputBlock.Text += "\n";
      }
   }
}
// The example displays the following output:
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 10): False
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
//    (1/16/2009 12:00:00 AM, 3, 5, 4) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
//    
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (4/22/2009 12:00:00 AM, 9, 14, 10): False
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (4/22/2009 12:00:00 AM, 9, 14, 11): True
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
//    
//    (4/22/2009 12:00:00 AM, 9, 14, 10) = (6/1/2009 12:00:00 AM, 23, 28, 21): False
//    (4/22/2009 12:00:00 AM, 9, 14, 10) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
//    (4/22/2009 12:00:00 AM, 9, 14, 10) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
//    
//    (6/1/2009 12:00:00 AM, 23, 28, 21) = (4/22/2009 12:00:00 AM, 9, 14, 11): False
//    (6/1/2009 12:00:00 AM, 23, 28, 21) = (9/6/2009 12:00:00 AM, 25, 30, 25): False
//    
//    (4/22/2009 12:00:00 AM, 9, 14, 11) = (9/6/2009 12:00:00 AM, 25, 30, 25): 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.