Tuple<T1,T2,T3,T4>.Item4 속성

정의

현재 Tuple<T1,T2,T3,T4> 개체의 네 번째 구성 요소 값을 가져옵니다.

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

속성 값

T4

현재 Tuple<T1,T2,T3,T4> 개체의 네 번째 구성 요소 값입니다.

예제

다음 예제에서는 구성 요소에 Tuple<T1,T2,T3,T4> 도시 이름, 연도의 월 및 해당 월의 평균 고온 및 최저 온도를 포함하는 개체의 배열을 정의합니다. 그런 다음 각 구성 요소의 값을 검색하고 표시합니다.

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
open System
open System.Globalization

let 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.
printfn "%41s" "Temperatures"
printfn "%-20s %5s    %4s  %4s\n" "City" "Month" "High" "Low"
for temperature in temperatures do
    printfn $"{temperature.Item1,-20} {DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(temperature.Item2 - 1),5}    {temperature.Item3,4:N1}  {temperature.Item4,4:N1}" 
// 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

설명

다음 두 가지 방법 중 하나로 구성 요소의 형식을 Item4 동적으로 확인할 수 있습니다.

  • 속성에서 GetType 반환되는 값에 대해 메서드를 호출합니다 Item4 .

  • 개체를 Type 나타내는 Tuple<T1,T2,T3,T4> 개체를 검색하고 해당 메서드에서 반환 Type.GetGenericArguments 되는 배열에서 네 번째 요소를 검색합니다.

적용 대상