Partager via


Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>.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, T7, TRest> 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 if it meets all the following conditions:

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

  • It has the same total number of components that are of the same types as the current instance.

  • Its components (including its nested components) have the same values as those of the current instance.

Examples

The following example defines five Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> objects that contain prime numbers. It then compares the first object with each of the remaining objects. As the output shows, only the first and the last Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> objects are equal, because they have an identical number of components with identical values.

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      ' Create five 8-tuple objects containing prime numbers.
      Dim prime1 = New Tuple(Of Int32, Int32, Int32, Int32, Int32, Int32, Int32, _
                           Tuple(Of Int32)) (2, 3, 5, 7, 11, 13, 17, _
                           New Tuple(Of Int32)(19)) 
      Dim prime2 = New Tuple(Of Int32, Int32, Int32, Int32, Int32, Int32, Int32, _
                           Tuple(Of Int32)) (23, 29, 31, 37, 41, 43, 47, _
                           New Tuple(Of Int32)(55)) 
      Dim prime3 = New Tuple(Of Int32, Int32, Int32, Int32, Int32, Int32, Int32, _
                           Tuple(Of Int32)) (3, 2, 5, 7, 11, 13, 17, _
                           New Tuple(Of Int32)(19)) 
      Dim prime4 = New Tuple(Of Int32, Int32, Int32, Int32, Int32, Int32, Int32, _
                           Tuple(Of Int32, Int32)) (2, 3, 5, 7, 11, 13, 17, _
                           New Tuple(Of Int32, Int32)(19, 23))
      Dim prime5 = New Tuple(Of Int32, Int32, Int32, Int32, Int32, Int32, Int32, _
                           Tuple(Of Int32)) (2, 3, 5, 7, 11, 13, 17, _
                           New Tuple(Of Int32)(19))
      outputBlock.Text += String.Format("{0} = {1} : {2}", prime1, prime2, prime1.Equals(prime2)) & vbCrLf
      outputBlock.Text += String.Format("{0} = {1} : {2}", prime1, prime3, prime1.Equals(prime3)) & vbCrLf
      outputBlock.Text += String.Format("{0} = {1} : {2}", prime1, prime4, prime1.Equals(prime4)) & vbCrLf
      outputBlock.Text += String.Format("{0} = {1} : {2}", prime1, prime5, prime1.Equals(prime5)) & vbCrLf
   End Sub
End Module
' The example displays the following output:
'    (2, 3, 5, 7, 11, 13, 17, 19) = (23, 29, 31, 37, 41, 43, 47, 55) : False
'    (2, 3, 5, 7, 11, 13, 17, 19) = (3, 2, 5, 7, 11, 13, 17, 19) : False
'    (2, 3, 5, 7, 11, 13, 17, 19) = (2, 3, 5, 7, 11, 13, 17, 19, 23) : False
'    (2, 3, 5, 7, 11, 13, 17, 19) = (2, 3, 5, 7, 11, 13, 17, 19) : True
using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Create five 8-tuple objects containing prime numbers.
      var prime1 = new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32,
                           Tuple<Int32>>(2, 3, 5, 7, 11, 13, 17,
                           new Tuple<Int32>(19));
      var prime2 = new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32,
                           Tuple<Int32>>(23, 29, 31, 37, 41, 43, 47,
                           new Tuple<Int32>(55));
      var prime3 = new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32,
                           Tuple<Int32>>(3, 2, 5, 7, 11, 13, 17,
                           new Tuple<Int32>(19));
      var prime4 = new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32,
                           Tuple<Int32, Int32>>(2, 3, 5, 7, 11, 13, 17,
                           new Tuple<Int32, Int32>(19, 23));
      var prime5 = new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32,
                           Tuple<Int32>>(2, 3, 5, 7, 11, 13, 17,
                           new Tuple<Int32>(19));
      outputBlock.Text += String.Format("{0} = {1} : {2}", prime1, prime2, prime1.Equals(prime2)) + "\n";
      outputBlock.Text += String.Format("{0} = {1} : {2}", prime1, prime3, prime1.Equals(prime3)) + "\n";
      outputBlock.Text += String.Format("{0} = {1} : {2}", prime1, prime4, prime1.Equals(prime4)) + "\n";
      outputBlock.Text += String.Format("{0} = {1} : {2}", prime1, prime5, prime1.Equals(prime5)) + "\n";
   }
}
// The example displays the following output:
//    (2, 3, 5, 7, 11, 13, 17, 19) = (23, 29, 31, 37, 41, 43, 47, 55) : False
//    (2, 3, 5, 7, 11, 13, 17, 19) = (3, 2, 5, 7, 11, 13, 17, 19) : False
//    (2, 3, 5, 7, 11, 13, 17, 19) = (2, 3, 5, 7, 11, 13, 17, 19, 23) : False
//    (2, 3, 5, 7, 11, 13, 17, 19) = (2, 3, 5, 7, 11, 13, 17, 19) : True

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.