Tuple<T1,T2,T3,T4>.Item2 Property

Definition

Ruft den Wert der zweiten Komponente des aktuellen Tuple<T1,T2,T3,T4>-Objekts ab.Gets the value of the current Tuple<T1,T2,T3,T4> object's second component.

public:
 property T2 Item2 { T2 get(); };
public T2 Item2 { get; }
member this.Item2 : 'T2
Public ReadOnly Property Item2 As T2

Property Value

T2

Der Wert der zweiten Komponente des aktuellen Tuple<T1,T2,T3,T4>-Objekts.The value of the current Tuple<T1,T2,T3,T4> object's second component.

Examples

Im folgenden Beispiel wird ein Array von Tuple<T1,T2,T3,T4> Objekten definiert, deren Komponenten den Namen einer Stadt, einen Monat des Jahres und den durchschnittlichen höchst-und Tiefstwert für diesen Monat enthalten.The following example defines an array of Tuple<T1,T2,T3,T4> objects whose components contain the name of a city, a month of the year, and the average high and low temperatures for that month. Anschließend wird der Wert der einzelnen Komponenten abgerufen und angezeigt.It then retrieves and displays the value of each component.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      Tuple<string, int, double, double>[] temperatures = 
            { Tuple.Create("New York, NY", 4, 61.0, 43.0),
              Tuple.Create("Chicago, IL", 2, 34.0, 18.0), 
              Tuple.Create("Newark, NJ", 4, 61.0, 43.0),
              Tuple.Create("Boston, MA", 6, 77.0, 59.0),
              Tuple.Create("Detroit, MI", 9, 74.0, 53.0),
              Tuple.Create("Minneapolis, MN", 8, 81.0, 61.0) }; 
      // Display the array of 4-tuple objects.
      Console.WriteLine("{0,41}", "Temperatures");
      Console.WriteLine("{0,-20} {1,5}    {2,4}  {3,4}\n", 
                        "City", "Month", "High", "Low");
      foreach (var temperature in temperatures)
         Console.WriteLine("{0,-20} {1,5}    {2,4:N1}  {3,4:N1}", 
                           temperature.Item1, 
                           DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(temperature.Item2 - 1), 
                           temperature.Item3, temperature.Item4);
   }
}
// The example displays the following output:
//                                    Temperatures
//       City                 Month    High   Low
//       
//       New York, NY           Mar    61.0  43.0
//       Chicago, IL            Jan    34.0  18.0
//       Newark, NJ             Mar    61.0  43.0
//       Boston, MA             May    77.0  59.0
//       Detroit, MI            Aug    74.0  53.0
//       Minneapolis, MN        Jul    81.0  61.0
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim temperatures() = 
             { Tuple.Create("New York, NY", 4, 61, 43), _
               Tuple.Create("Chicago, IL", 2, 34, 18), _ 
               Tuple.Create("Newark, NJ", 4, 61, 43), _
               Tuple.Create("Boston, MA", 6, 77, 59), _
               Tuple.Create("Detroit, MI", 9, 74, 53), _
               Tuple.Create("Minneapolis, MN", 8, 81, 61) } 
      ' Display the array of 4-tuples.
      Console.WriteLine("{0,41}", "Temperatures")
      Console.WriteLine("{0,-20} {1,5}    {2,4}  {3,4}", 
                        "City", "Month", "High", "Low")
      Console.WriteLine()
      For Each temperature In temperatures
         Console.WriteLine("{0,-20} {1,5}    {2,4:N1}  {3,4:N1}", 
                           temperature.Item1, 
                           DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(temperature.Item2 - 1), 
                           temperature.Item3, temperature.Item4)
      Next
   End Sub
End Module
' The example displays the following output:
'                                    Temperatures
'       City                 Month    High   Low
'       
'       New York, NY           Mar    61.0  43.0
'       Chicago, IL            Jan    34.0  18.0
'       Newark, NJ             Mar    61.0  43.0
'       Boston, MA             May    77.0  59.0
'       Detroit, MI            Aug    74.0  53.0
'       Minneapolis, MN        Jul    81.0  61.0

Remarks

Der Typ der Item2 Komponente kann auf zwei Arten dynamisch bestimmt werden:You can dynamically determine the type of the Item2 component in one of two ways:

  • Durch Aufrufen der GetType-Methode für den Wert, der von der Item2-Eigenschaft zurückgegeben wird.By calling the GetType method on the value that is returned by the Item2 property.

  • Durch Abrufen des Type Objekts, das das Tuple<T1,T2,T3,T4> Objekt darstellt, und Abrufen des zweiten Elements aus dem Array, das von seiner Type.GetGenericArguments-Methode zurückgegeben wird.By retrieving the Type object that represents the Tuple<T1,T2,T3,T4> object, and retrieving the second element from the array that is returned by its Type.GetGenericArguments method.

Applies to