Lire en anglais Modifier

Partager via


Tuple<T1>.Item1 Property

Definition

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

C#
public T1 Item1 { get; }

Property Value

T1

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

Examples

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

C#
using System;
using System.Numerics;

public class Example
{
   public static void Main()
   {
      var tuple1 = Tuple.Create(-1.23445e-32);
      // Display information about this singleton.
      Type tuple1Type = tuple1.GetType();
      Console.WriteLine("First 1-Tuple:");
      Console.WriteLine("   Type: {0}", tuple1Type.Name);
      Console.WriteLine("   Generic Parameter Type: {0}", 
                        tuple1Type.GetGenericArguments()[0]);
      Console.WriteLine("   Component Value: {0}", tuple1.Item1);
      Console.WriteLine("   Component Value Type: {0}", 
                        tuple1.Item1.GetType().Name);
      Console.WriteLine();
      
      var tuple2 = Tuple.Create((BigInteger)1.83789322281780983781356676e103);
      // Display information about this singleton.
      Type tuple2Type = tuple2.GetType();
      Console.WriteLine("Second 1-Tuple:");
      Console.WriteLine("   Type: {0}", tuple2Type.Name);
      Console.WriteLine("   Generic Parameter Type: {0}", 
                        tuple2Type.GetGenericArguments()[0]);
      Console.WriteLine("   Component Value: {0}", tuple2.Item1);
      Console.WriteLine("   Component Value Type: {0}", 
                        tuple2.Item1.GetType().Name);
   }
}
// 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.Numerics.BigInteger
//          Component Value: 1.8378932228178098168858909492E+103
//          Component Value Type: BigInteger

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.

Applies to

Produit Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0