Tuple<T1,T2,T3,T4,T5,T6,T7>.Item4 属性
定义
获取当前 Tuple<T1,T2,T3,T4,T5,T6,T7> 对象的第四个分量的值。Gets the value of the current Tuple<T1,T2,T3,T4,T5,T6,T7> object's fourth component.
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,T5,T6,T7> 对象的第四个分量的值。The value of the current Tuple<T1,T2,T3,T4,T5,T6,T7> object's fourth component.
示例
下面的示例定义了一个对象数组,这些 Tuple<T1,T2,T3,T4,T5,T6,T7> 对象的组件包含三个美国城市 (纽约、芝加哥和洛杉矶) 从1950到2000的人口数据。The following example defines an array of Tuple<T1,T2,T3,T4,T5,T6,T7> objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. 然后,它会显示一个列出数据的表。It then displays a table that lists the data. 若要显示1970中的人口,它将检索 Item4 每个对象的属性值 Tuple<T1,T2,T3,T4,T5,T6,T7> 。To display the population in 1970, it retrieves the value of the Item4 property for each Tuple<T1,T2,T3,T4,T5,T6,T7> object.
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, int>[] cities =
{ Tuple.Create("New York", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278),
Tuple.Create("Los Angeles", 1970358, 2479015, 2816061, 2966850, 3485398, 3694820),
Tuple.Create("Chicago", 3620962, 3550904, 3366957, 3005072, 2783726, 2896016) };
// Display tuple data in table.
string header = "Population in";
Console.WriteLine("{0,-12} {1,66}",
"City", new String('-',(66-header.Length)/2) + header +
new String('-', (66-header.Length)/2));
Console.WriteLine("{0,24}{1,11}{2,11}{3,11}{4,11}{5,11}\n",
"1950", "1960", "1970", "1980", "1990", "2000");
foreach (var city in cities)
Console.WriteLine("{0,-12} {1,11:N0}{2,11:N0}{3,11:N0}{4,11:N0}{5,11:N0}{6,11:N0}",
city.Item1, city.Item2, city.Item3, city.Item4,
city.Item5, city.Item6, city.Item7);
}
}
// The example displays the following output:
// City --------------------------Population in--------------------------
// 1950 1960 1970 1980 1990 2000
//
// New York 7,891,957 7,781,984 7,894,862 7,071,639 7,322,564 8,008,278
// Los Angeles 1,970,358 2,479,015 2,816,061 2,966,850 3,485,398 3,694,820
// Chicago 3,620,962 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", 7891957, 7781984, 7894862,
7071639, 7322564, 8008278),
Tuple.Create("Los Angeles", 1970358, 2479015, 2816061,
2966850, 3485398, 3694820),
Tuple.Create("Chicago", 3620962, 3550904, 3366957,
3005072, 2783726, 2896016) }
' Display tuple data in table.
Dim header As String = "Population in"
Console.WriteLine("{0,-12} {1,66}",
"City", New String("-"c,(66-header.Length)\2) + header + _
New String("-"c, (66-header.Length)\2))
Console.WriteLine("{0,24}{1,11}{2,11}{3,11}{4,11}{5,11}",
"1950", "1960", "1970", "1980", "1990", "2000")
Console.WriteLine()
For Each city In cities
Console.WriteLine("{0,-12} {1,11:N0}{2,11:N0}{3,11:N0}{4,11:N0}{5,11:N0}{6,11:N0}",
city.Item1, city.Item2, city.Item3, city.Item4,
city.Item5, city.Item6, city.Item7)
Next
End Sub
End Module
' The example displays the following output:
' City --------------------------Population in--------------------------
' 1950 1960 1970 1980 1990 2000
'
' New York 7,891,957 7,781,984 7,894,862 7,071,639 7,322,564 8,008,278
' Los Angeles 1,970,358 2,479,015 2,816,061 2,966,850 3,485,398 3,694,820
' Chicago 3,620,962 3,550,904 3,366,957 3,005,072 2,783,726 2,896,016
注解
可以 Item4 通过以下两种方式之一动态确定组件的类型:You can dynamically determine the type of the Item4 component in one of two ways:
通过
GetType对属性返回的值调用方法 Item4 。By calling theGetTypemethod on the value that is returned by the Item4 property.通过检索 Type 表示对象的对象 Tuple<T1,T2,T3,T4,T5,T6,T7> ,并从其方法返回的数组中检索第四个元素 Type.GetGenericArguments 。By retrieving the Type object that represents the Tuple<T1,T2,T3,T4,T5,T6,T7> object, and retrieving the fourth element from the array that is returned by its Type.GetGenericArguments method.