C# Tuple Item1

Description

Tuple Item1 gets the value of the Tuple object's single component.

Syntax

Tuple<T1>.Item1 has the following syntax.


public T1 Item1 { get; }

Example

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


/* w  w  w .ja v a 2s .  c om*/
using System;

public class Example
{
   public static void Main()
   {
      var tuple1 = Tuple.Create(-1.23445e-32);
      Type tuple1Type = tuple1.GetType();
      Console.WriteLine(tuple1Type.Name);
      Console.WriteLine(tuple1Type.GetGenericArguments()[0]);
      Console.WriteLine(tuple1.Item1);
      Console.WriteLine(tuple1.Item1.GetType().Name);

      var tuple2 = Tuple.Create(1.837);

      Type tuple2Type = tuple2.GetType();
      Console.WriteLine(tuple2Type.Name);
      Console.WriteLine(tuple2Type.GetGenericArguments()[0]);
      Console.WriteLine(tuple2.Item1);
      Console.WriteLine(tuple2.Item1.GetType().Name);
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version