Export (0) Print
Expand All

Tuple<T1>.Item1 Property

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

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

public T1 Item1 { get; }

Property Value

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

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.

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


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


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