語言

Tuple<T1,T2>(T1, T2) 建構函式

定義

初始化 Tuple<T1,T2> 類別的新執行個體。

public:
 Tuple(T1 item1, T2 item2);
public Tuple(T1 item1, T2 item2);
new Tuple<'T1, 'T2> : 'T1 * 'T2 -> Tuple<'T1, 'T2>
Public Sub New (item1 As T1, item2 As T2)

參數

item1
T1

元組的第一個組件值。

item2
T2

元組第二成分的值。

備註

你也可以用靜態 Tuple.Create<T1,T2>(T1, T2) 方法實例化一個兩元組物件,而不必明確指定其組件的類型。 以下範例使用該 Tuple.Create<T1,T2>(T1, T2) 方法實例化一個 2-元組,其組件型別為 StringDouble和 。

var tuple2 = Tuple.Create("New York", 32.68);
Console.WriteLine("{0}: {1}", tuple2.Item1, tuple2.Item2);
// Displays New York: 32.68
let tuple2 = Tuple.Create("New York", 32.68)
printfn $"{tuple2.Item1}: {tuple2.Item2}"
// Displays New York: 32.68
Dim tuple2 = Tuple.Create("New York", 32.68)
Console.WriteLine("{0}: {1}", tuple2.Item1, tuple2.Item2)
' Displays New York: 32.68

這等同於以下對 Tuple<T1,T2> 類別建構器的呼叫。

var tuple2 = new Tuple<string, double>("New York", 32.68);
Console.WriteLine("{0}: {1}", tuple2.Item1, tuple2.Item2);
// Displays New York: 32.68
let tuple2 = Tuple<string, double>("New York", 32.68)
printfn $"{tuple2.Item1}: {tuple2.Item2}"
// Displays New York: 32.68
Dim tuple2 = New Tuple(Of String, Double)("New York", 32.68)
Console.WriteLine("{0}: {1}", tuple2.Item1, tuple2.Item2)
' Displays New York: 32.68

適用於