Tuple<T1,T2,T3,T4,T5,T6>.Item5 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得目前 Tuple<T1,T2,T3,T4,T5,T6> 物件之第五個元件的值。
public:
property T5 Item5 { T5 get(); };
public T5 Item5 { get; }
member this.Item5 : 'T5
Public ReadOnly Property Item5 As T5
屬性值
- T5
目前 Tuple<T1,T2,T3,T4,T5,T6> 物件第五個元件的值。
範例
下列範例會定義 物件的陣列 Tuple<T1,T2,T3,T4,T5,T6> ,其元件包含 2000 年 1960 年到 2000 年 1960 年三個美國城市 (、芝加哥和) 洛杉磯的母體資料。 然後會顯示列出資料的資料表。 若要在 1990 中顯示母體擴展,它會擷取 Item5 每個 Tuple<T1,T2,T3,T4,T5,T6> 物件的 屬性值。
using System;
using System.Text.RegularExpressions;
public class Class1
{
public static void Main()
{
// Create tuples containing population data for New York, Chicago,
// and Los Angeles, 1960-2000.
Tuple<string, int, int, int, int, int>[] cities =
{ Tuple.Create("New York", 7781984, 7894862, 7071639, 7322564, 8008278),
Tuple.Create("Los Angeles", 2479015, 2816061, 2966850, 3485398, 3694820),
Tuple.Create("Chicago", 3550904, 3366957, 3005072, 2783726, 2896016) };
// Display tuple data in table.
string header = "Population in";
Console.WriteLine("{0,-12} {1,60}",
"City", new String('-',(60-header.Length)/2) + header +
new String('-', (60-header.Length)/2));
Console.WriteLine("{0,25}{1,12}{2,12}{3,12}{4,12}\n",
"1960", "1970", "1980", "1990", "2000");
foreach (var city in cities)
Console.WriteLine("{0,-12} {1,12:N0}{2,12:N0}{3,12:N0}{4,12:N0}{5,12:N0}",
city.Item1, city.Item2, city.Item3, city.Item4,
city.Item5, city.Item6);
}
}
// The example displays the following output:
// City -----------------------Population in-----------------------
// 1960 1970 1980 1990 2000
//
// New York 7,781,984 7,894,862 7,071,639 7,322,564 8,008,278
// Los Angeles 2,479,015 2,816,061 2,966,850 3,485,398 3,694,820
// Chicago 3,550,904 3,366,957 3,005,072 2,783,726 2,896,016
open System
// Create tuples containing population data for New York, Chicago,
// and Los Angeles, 1960-2000.
let cities =
[| Tuple.Create("New York", 7781984, 7894862, 7071639, 7322564, 8008278)
Tuple.Create("Los Angeles", 2479015, 2816061, 2966850, 3485398, 3694820)
Tuple.Create("Chicago", 3550904, 3366957, 3005072, 2783726, 2896016) |]
// Display tuple data in table.
let header = "Population in"
printfn $"""{"City",-12} {String('-',(60 - header.Length) / 2) + header + String('-', (60 - header.Length) / 2),60}"""
printfn "%25s%12s%12s%12s%12s\n" "1960" "1970" "1980" "1990" "2000"
for city in cities do
printfn $"{city.Item1,-12} {city.Item2,12:N0}{city.Item3,12:N0}{city.Item4,12:N0}{city.Item5,12:N0}{city.Item6,12:N0}"
// The example displays the following output:
// City -----------------------Population in-----------------------
// 1960 1970 1980 1990 2000
//
// New York 7,781,984 7,894,862 7,071,639 7,322,564 8,008,278
// Los Angeles 2,479,015 2,816,061 2,966,850 3,485,398 3,694,820
// Chicago 3,550,904 3,366,957 3,005,072 2,783,726 2,896,016
Module Example
Public Sub Main()
' Create tuples containing population data for New York, Chicago,
' and Los Angeles, 1960-2000.
Dim cities() =
{ Tuple.Create("New York", 7781984, 7894862,
7071639, 7322564, 8008278),
Tuple.Create("Los Angeles", 2479015, 2816061,
2966850, 3485398, 3694820),
Tuple.Create("Chicago", 3550904, 3366957,
3005072, 2783726, 2896016) }
' Display tuple data in table.
Dim header As String = "Population in"
Console.WriteLine("{0,-12} {1,60}",
"City", New String("-"c,(60-header.Length)\2) + header + _
New String("-"c, (60-header.Length)\2))
Console.WriteLine("{0,25}{1,12}{2,12}{3,12}{4,12}",
"1960", "1970", "1980", "1990", "2000")
Console.WriteLine()
For Each city In cities
Console.WriteLine("{0,-12} {1,12:N0}{2,12:N0}{3,12:N0}{4,12:N0}{5,12:N0}",
city.Item1, city.Item2, city.Item3, city.Item4,
city.Item5, city.Item6)
Next
End Sub
End Module
' The example displays the following output:
' City -----------------------Population in-----------------------
' 1960 1970 1980 1990 2000
'
' New York 7,781,984 7,894,862 7,071,639 7,322,564 8,008,278
' Los Angeles 2,479,015 2,816,061 2,966,850 3,485,398 3,694,820
' Chicago 3,550,904 3,366,957 3,005,072 2,783,726 2,896,016
備註
您可以使用下列兩種方式之 Item5 一,動態判斷元件的類型:
藉由在 屬性所 Item5 傳回的值上呼叫
GetType
方法。擷取 Type 代表 Tuple<T1,T2,T3,T4,T5,T6> 物件的 物件,並從其 Type.GetGenericArguments 方法傳回的陣列中擷取第一個專案。