다음을 통해 공유


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

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

Gets the value of the current Tuple<T1, T2, T3, T4> object's second component.

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

Syntax

'Declaration
Public ReadOnly Property Item2 As T2
public T2 Item2 { get; }

Property Value

Type: T2
The value of the current Tuple<T1, T2, T3, T4> object's second component.

Remarks

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

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

  • 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.

Examples

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. It then retrieves and displays the value of each component.

Imports System.Globalization

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      outputBlock.FontFamily = New System.Windows.Media.FontFamily("Courier New")

      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.
      outputBlock.Text &= String.Format("{0,41}", "Temperatures") & vbCrLf
      outputBlock.Text += String.Format("{0,-20} {1,5}    {2,4}  {3,4}", _
                        "City", "Month", "High", "Low") + vbCrLf
      outputBlock.Text &= vbCrLf
      For Each temperature In temperatures
         outputBlock.Text += String.Format("{0,-20} {1,5}    {2,4:N1}  {3,4:N1}", _
                           temperature.Item1, _
                           DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(temperature.Item2 - 1), _ 
                           temperature.Item3, temperature.Item4) & vbCrLf
      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
using System;
using System.Globalization;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.FontFamily = new System.Windows.Media.FontFamily("Courier New");
      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.
      outputBlock.Text += String.Format("{0,41}\n", "Temperatures");
      outputBlock.Text += String.Format("{0,-20} {1,5}    {2,4}  {3,4}\n\n",
                        "City", "Month", "High", "Low");
      foreach (var temperature in temperatures)
         outputBlock.Text += String.Format("{0,-20} {1,5}    {2,4:N1}  {3,4:N1}",
                           temperature.Item1,
                           DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(temperature.Item2 - 1),
                           temperature.Item3, temperature.Item4) + "\n";
   }
}
// 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

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.