Tuple<T1>.Item1 Property

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

Gets the value of the Tuple<T1> object's single component.

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

Syntax

'Declaration
Public ReadOnly Property Item1 As T1
public T1 Item1 { get; }

Property Value

Type: T1
The value of the current Tuple<T1> object's single component.

Remarks

You can determine the type of the Item1 component in one of two ways:

  • By calling the GetType method on the value that is returned by the Item1 property.

  • By retrieving the Type object that represents the Tuple<T1> object, and retrieving the first element from the array that is returned by its Type.GetGenericArguments method.

The example illustrates both approaches.

Examples

The following example displays information about two singletons and their components.

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim tuple1 = Tuple.Create(-1.23445E-32)
      ' Display information about this singleton.
      Dim tuple1Type As Type = tuple1.GetType()
      outputBlock.Text &= "First 1-Tuple:" & vbCrLf
      outputBlock.Text += String.Format("   Type: {0}", tuple1Type.Name) & vbCrLf
      outputBlock.Text += String.Format("   Generic Parameter Type: {0}", _
                        tuple1Type.GetGenericArguments()(0)) + vbCrLf
      outputBlock.Text += String.Format("   Component Value: {0}", tuple1.Item1) + vbCrLf
      outputBlock.Text += String.Format("   Component Value Type: {0}", _
                        tuple1.Item1.GetType().Name) + vbCrLf
      outputBlock.Text &= vbCrLf

      Dim tuple2 As New Tuple(Of Single)(1.83789e103)
      ' Display information about this singleton.
      Dim tuple2Type As Type = tuple2.GetType()
      outputBlock.Text &= "Second 1-Tuple:" & vbCrLf
      outputBlock.Text += String.Format("   Type: {0}", tuple2Type.Name) & vbCrLf
      outputBlock.Text += String.Format("   Generic Parameter Type: {0}", _
                        tuple2Type.GetGenericArguments()(0)) & vbCrLf
      outputBlock.Text += String.Format("   Component Value: {0}", tuple2.Item1) & vbCrLf
      outputBlock.Text += String.Format("   Component Value Type: {0}", _
                        tuple2.Item1.GetType().Name) & vbCrLf
   End Sub
End Module
' The example displays the following output:
'       First 1-Tuple:
'          Type: Tuple`1
'          Generic Parameter Type: System.Double
'          Component Value: -1.23445E-32
'          Component Value Type: Double
'       
'       Second 1-Tuple:
'          Type: Tuple`1
'          Generic Parameter Type: System.Single
'          Component Value: Infinity
'          Component Value Type: Single
using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      var tuple1 = Tuple.Create(-1.23445e-32);
      // Display information about this singleton.
      Type tuple1Type = tuple1.GetType();
      outputBlock.Text += "First 1-Tuple:" + "\n";
      outputBlock.Text += String.Format("   Type: {0}", tuple1Type.Name) + "\n";
      outputBlock.Text += String.Format("   Generic Parameter Type: {0}",
                        tuple1Type.GetGenericArguments()[0]) + "\n";
      outputBlock.Text += String.Format("   Component Value: {0}", tuple1.Item1) + "\n";
      outputBlock.Text += String.Format("   Component Value Type: {0}",
                        tuple1.Item1.GetType().Name) + "\n";
      outputBlock.Text += "\n";

      var tuple2 = Tuple.Create((float)1.83789e103);
      // Display information about this singleton.
      Type tuple2Type = tuple2.GetType();
      outputBlock.Text += "Second 1-Tuple:" + "\n";
      outputBlock.Text += String.Format("   Type: {0}", tuple2Type.Name) + "\n";
      outputBlock.Text += String.Format("   Generic Parameter Type: {0}",
                        tuple2Type.GetGenericArguments()[0]) + "\n";
      outputBlock.Text += String.Format("   Component Value: {0}", tuple2.Item1) + "\n";
      outputBlock.Text += String.Format("   Component Value Type: {0}",
                        tuple2.Item1.GetType().Name) + "\n";
   }
}
// The example displays the following output:
//       First 1-Tuple:
//          Type: Tuple`1
//          Generic Parameter Type: System.Double
//          Component Value: -1.23445E-32
//          Component Value Type: Double
//       
//       Second 1-Tuple:
//          Type: Tuple`1
//          Generic Parameter Type: System.Single
//          Component Value: Infinity
//          Component Value Type: Single

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.

See Also

Reference