Tuple<T1>.Item1 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 Tuple<T1> 物件之單一元件的值。
public:
property T1 Item1 { T1 get(); };
public T1 Item1 { get; }
member this.Item1 : 'T1
Public ReadOnly Property Item1 As T1
屬性值
- T1
目前 Tuple<T1> 物件之單一元件的值。
範例
下列範例會顯示兩個單一專案及其元件的相關資訊。
using System;
using System.Numerics;
public class Example
{
public static void Main()
{
var tuple1 = Tuple.Create(-1.23445e-32);
// Display information about this singleton.
Type tuple1Type = tuple1.GetType();
Console.WriteLine("First 1-Tuple:");
Console.WriteLine(" Type: {0}", tuple1Type.Name);
Console.WriteLine(" Generic Parameter Type: {0}",
tuple1Type.GetGenericArguments()[0]);
Console.WriteLine(" Component Value: {0}", tuple1.Item1);
Console.WriteLine(" Component Value Type: {0}",
tuple1.Item1.GetType().Name);
Console.WriteLine();
var tuple2 = Tuple.Create((BigInteger)1.83789322281780983781356676e103);
// Display information about this singleton.
Type tuple2Type = tuple2.GetType();
Console.WriteLine("Second 1-Tuple:");
Console.WriteLine(" Type: {0}", tuple2Type.Name);
Console.WriteLine(" Generic Parameter Type: {0}",
tuple2Type.GetGenericArguments()[0]);
Console.WriteLine(" Component Value: {0}", tuple2.Item1);
Console.WriteLine(" Component Value Type: {0}",
tuple2.Item1.GetType().Name);
}
}
// The example displays the following output:
// First 1-Tuple:
// Type: Tuple`1
// Generic Parameter Type: System.Double
// Component Value: -1.23445E-32
// Component Value Type: Double
//
// Second 1-Tuple:
// Type: Tuple`1
// Generic Parameter Type: System.Numerics.BigInteger
// Component Value: 1.8378932228178098168858909492E+103
// Component Value Type: BigInteger
open System
let tuple1 = Tuple.Create -1.23445e-32
// Display information about this singleton.
let tuple1Type = tuple1.GetType()
printfn "First 1-Tuple:"
printfn $" Type: {tuple1Type.Name}"
printfn $" Generic Parameter Type: {tuple1Type.GetGenericArguments()[0]}"
printfn $" Component Value: {tuple1.Item1}"
printfn $" Component Value Type: {tuple1.Item1.GetType().Name}\n"
let tuple2 = Tuple.Create(bigint 1.83789322281780983781356676e103)
// Display information about this singleton.
let tuple2Type = tuple2.GetType()
printfn "Second 1-Tuple:"
printfn $" Type: {tuple2Type.Name}"
printfn $" Generic Parameter Type: {tuple2Type.GetGenericArguments()[0]}"
printfn $" Component Value: {tuple2.Item1}"
printfn $" Component Value Type: {tuple2.Item1.GetType().Name}"
// The example displays the following output:
// First 1-Tuple:
// Type: Tuple`1
// Generic Parameter Type: System.Double
// Component Value: -1.23445E-32
// Component Value Type: Double
//
// Second 1-Tuple:
// Type: Tuple`1
// Generic Parameter Type: System.Numerics.BigInteger
// Component Value: 1.8378932228178098168858909492E+103
// Component Value Type: BigInteger
Imports System.Numerics
Module modMain
Public Sub Main()
Dim tuple1 = Tuple.Create(-1.23445e-32)
' Display information about this singleton.
Dim tuple1Type As Type = tuple1.GetType()
Console.WriteLine("First 1-Tuple:")
Console.WriteLine(" Type: {0}", tuple1Type.Name)
Console.WriteLine(" Generic Parameter Type: {0}",
tuple1Type.GetGenericArguments()(0))
Console.WriteLine(" Component Value: {0}", tuple1.Item1)
Console.WriteLine(" Component Value Type: {0}",
tuple1.Item1.GetType().Name)
Console.WriteLine()
Dim tuple2 As New Tuple(Of BigInteger)(1.83789322281780983781356676e103)
' Display information about this singleton.
Dim tuple2Type As Type = tuple2.GetType()
Console.WriteLine("Second 1-Tuple:")
Console.WriteLine(" Type: {0}", tuple2Type.Name)
Console.WriteLine(" Generic Parameter Type: {0}",
tuple2Type.GetGenericArguments()(0))
Console.WriteLine(" Component Value: {0}", tuple2.Item1)
Console.WriteLine(" Component Value Type: {0}",
tuple2.Item1.GetType().Name)
End Sub
End Module
' The example displays the following output:
' First 1-Tuple:
' Type: Tuple`1
' Generic Parameter Type: System.Double
' Component Value: -1.23445E-32
' Component Value Type: Double
'
' Second 1-Tuple:
' Type: Tuple`1
' Generic Parameter Type: System.Numerics.BigInteger
' Component Value: 1.8378932228178098168858909492E+103
' Component Value Type: BigInteger
備註
您可以使用下列兩種方式之一來判斷元件的類型 Item1 :
藉由在 屬性所 Item1 傳回的值上呼叫
GetType
方法。擷取 Type 代表 Tuple<T1> 物件的 物件,並從其 Type.GetGenericArguments 方法傳回的陣列中擷取第一個專案。
此範例說明這兩種方法。