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> 对象,其组件包含从 1960 年到 2000 年 (纽约、芝加哥和) 洛杉矶三个城市的人口数据。 然后,它会显示一个列出数据的表。 若要在 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 方法返回的数组中检索第一个元素。