Tuple<T1,T2,T3,T4>.Item4 属性
定义
获取当前 Tuple<T1,T2,T3,T4> 对象的第四个分量的值。Gets the value of the current Tuple<T1,T2,T3,T4> 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> 对象的第四个分量的值。The value of the current Tuple<T1,T2,T3,T4> object's fourth component.
示例
下面的示例定义了一个对象的数组 Tuple<T1,T2,T3,T4> ,这些对象的组件包含城市名称、一年中的月份以及该月的平均高温和低温度。The following example defines an array of Tuple<T1,T2,T3,T4> objects whose components contain the name of a city, a month of the year, and the average high and low temperatures for that month. 然后检索并显示每个组件的值。It then retrieves and displays the value of each component.
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
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 通过以下两种方式之一动态确定组件的类型:You can dynamically determine the type of the Item4 component in one of two ways:
通过
GetType
对属性返回的值调用方法 Item4 。By calling theGetType
method on the value that is returned by the Item4 property.通过检索 Type 表示对象的对象 Tuple<T1,T2,T3,T4> ,并从其方法返回的数组中检索第四个元素 Type.GetGenericArguments 。By retrieving the Type object that represents the Tuple<T1,T2,T3,T4> object, and retrieving the fourth element from the array that is returned by its Type.GetGenericArguments method.