Tuple<T1,T2,T3,T4,T5>.Item4 屬性

定義

取得目前 Tuple<T1,T2,T3,T4,T5> 物件之第四個元件的值。

C#
public T4 Item4 { get; }

屬性值

T4

目前 Tuple<T1,T2,T3,T4,T5> 物件之第四個元件的值。

範例

下列範例會定義 物件的陣列 Tuple<T1,T2,T3,T4,T5> ,其元件包含美國中狀態的名稱、其母體在 1990 年和 2000 年的母體擴展變更,以及其母體擴展中的百分比變更。 然後逐一查看陣列,並顯示 Tuple 中每個元件的值。

C#
using System;

public class Example
{
   public static void Main()
   {
      // Define array of tuples reflecting population change by state, 1990-2000.
      Tuple<string, int, int, int, double>[] statesData = 
         { Tuple.Create("California", 29760021, 33871648, 4111627, 13.8), 
           Tuple.Create("Illinois", 11430602, 12419293, 988691, 8.6), 
           Tuple.Create("Washington", 4866692, 5894121, 1027429, 21.1) };

      // Display the items of each tuple
      Console.WriteLine("{0,-12}{1,18}{2,18}{3,15}{4,12}\n", "State", 
                        "Population 1990", "Population 2000", "Change", 
                        "% Change");
      foreach(Tuple<string, int, int, int, double> stateData in statesData)
         Console.WriteLine("{0,-12}{1,18:N0}{2,18:N0}{3,15:N0}{4,12:P1}", 
                           stateData.Item1, stateData.Item2, 
                           stateData.Item3, stateData.Item4, stateData.Item5/100);      
   }
}
// The example displays the following output:
//    State          Population 1990   Population 2000         Change    % Change
//    
//    California          29,760,021        33,871,648      4,111,627      13.8 %
//    Illinois            11,430,602        12,419,293        988,691       8.6 %
//    Washington           4,866,692         5,894,121      1,027,429      21.1 %

備註

您可以使用下列兩種方式之 Item2 一,動態判斷元件的類型:

適用於

產品 版本
.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, 10
.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