Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>(T1, T2, T3, T4, T5, T6, T7, TRest) 建構函式

定義

初始化 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 類別的新執行個體。Initializes a new instance of the Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> class.

public:
 Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest);
public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest);
new Tuple<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7, 'Rest> : 'T1 * 'T2 * 'T3 * 'T4 * 'T5 * 'T6 * 'T7 * 'Rest -> Tuple<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7, 'Rest>
Public Sub New (item1 As T1, item2 As T2, item3 As T3, item4 As T4, item5 As T5, item6 As T6, item7 As T7, rest As TRest)

參數

item1
T1

Tuple 第 1 個元件的值。The value of the tuple's first component.

item2
T2

Tuple 第 2 個元件的值。The value of the tuple's second component.

item3
T3

Tuple 第 3 個元件的值。The value of the tuple's third component.

item4
T4

Tuple 第 4 個元件的值。The value of the tuple's fourth component

item5
T5

Tuple 第 5 個元件的值。The value of the tuple's fifth component.

item6
T6

Tuple 第 6 個元件的值。The value of the tuple's sixth component.

item7
T7

Tuple 第 7 個元件的值。The value of the tuple's seventh component.

rest
TRest

包含 Tuple 其餘元件之值的任何泛型 Tuple 物件。Any generic Tuple object that contains the values of the tuple's remaining components.

例外狀況

rest 不是泛型 Tuple 物件。rest is not a generic Tuple object.

範例

下列範例會建立17個元組,其中包含底特律(密歇根州)之城市的人口資料(從1860到2000的每次人口普查)。The following example creates a 17-tuple that contains population data for the city of Detroit, Michigan, for each census from 1860 to 2000. 元組的第一個元件是城市名稱。The first component of the tuple is the city name. 第二個元件是一系列資料的開始日期,而第三個元件則是開始日期的人口。The second component is the start date of the series of data, and the third component is the population at the start date. 每個後續元件都會提供10年間隔的人口。Each subsequent component provides the population at decade intervals. 此範例會使用兩層的嵌套來建立17元組:它會定義7個元組,其第三個到第七個元件包含1860到1900的人口資料、包含1910到1970之人口資料的嵌套7元組,以及內部的 nested 3-元組,其中包含1980到2000的人口資料。The example uses two layers of nesting to create the 17-tuple: It defines a 7-tuple whose third through seventh components contain population data for 1860 through 1900, a nested 7-tuple that contains population data for 1910 through 1970, and an inner nested 3-tuple that contains population data for 1980 through 2000.

var from1980 = Tuple.Create(1203339, 1027974, 951270);
var from1910 = new Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>> 
    (465766, 993078, 1568622, 1623452, 1849568, 1670144, 1511462, from1980);
var population = new Tuple<string, int, int, int, int, int, int,
    Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>> 
    ("Detroit", 1860, 45619, 79577, 116340, 205876, 285704, from1910);
Dim from1980 = Tuple.Create(1203339, 1027974, 951270)
Dim from1910 As New Tuple(Of Integer, Integer, Integer, Integer, Integer, Integer, Integer, _
    Tuple(Of Integer, Integer, Integer)) _
    (465766, 993078, 1568622, 1623452, 1849568, 1670144, 1511462, from1980)
Dim population As New Tuple(Of String, Integer, Integer, Integer, Integer, Integer, Integer, _ 
    Tuple(Of Integer, Integer, Integer, Integer, Integer, Integer, Integer, Tuple(Of Integer, Integer, Integer))) _
    ("Detroit", 1860, 45619, 79577, 116340, 205876, 285704, from1910)

備註

您也可以使用靜態 Tuple.Create 方法來具現化8元組(octuple)物件,而不需要明確指定其元件的類型。You can also use the static Tuple.Create method to instantiate an 8-tuple (octuple) object without having to explicitly specify the types of its components. 下列範例會使用 Tuple.Create 方法來具現化包含小於20之質數的8元組物件。The following example uses the Tuple.Create method to instantiate an 8-tuple object that contains prime numbers that are less than 20.

var primes = Tuple.Create(2, 3, 5, 7, 11, 13, 17, 19);
Console.WriteLine("Prime numbers less than 20: " + 
                  "{0}, {1}, {2}, {3}, {4}, {5}, {6}, and {7}",
                  primes.Item1, primes.Item2, primes.Item3, 
                  primes.Item4, primes.Item5, primes.Item6,
                  primes.Item7, primes.Rest.Item1);
// The example displays the following output:
//    Prime numbers less than 20: 2, 3, 5, 7, 11, 13, 17, and 19
Dim primes = Tuple.Create(2, 3, 5, 7, 11, 13, 17, 19)
Console.WriteLine("Prime numbers less than 20: " + 
                  "{0}, {1}, {2}, {3}, {4}, {5}, {6}, and {7}",
                  primes.Item1, primes.Item2, primes.Item3, 
                  primes.Item4, primes.Item5, primes.Item6,
                  primes.Item7, primes.Rest.Item1)
' The example displays the following output:
'     Prime numbers less than 20: 2, 3, 5, 7, 11, 13, 17, and 19

這相當於下列 Tuple<T1,T2,T3,T4,T5,T6,T7> 類別的函式呼叫。This is equivalent to the following call to the Tuple<T1,T2,T3,T4,T5,T6,T7> class constructor.

var primes = new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32,  
             Tuple<Int32>> (2, 3, 5, 7, 11, 13, 17, new Tuple<Int32>(19));
Dim primes = New Tuple(Of Int32, Int32, Int32, Int32, Int32, Int32, Int32, _ 
             Tuple(Of Int32))(2, 3, 5, 7, 11, 13, 17, New Tuple(Of Int32)(19))

不過,靜態 Tuple.Create 方法無法用來建立具有8個以上元件的元組物件。However, the static Tuple.Create method cannot be used to create a tuple object with more than eight components.

使用 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 的函式來建立包含八個或多個元件的 n 元組時,您可以使用 rest 參數來建立具有一個到七個元件的嵌套 n 元組。When using the Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> constructor to create an n-tuple with eight or more components, you use the rest parameter to create a nested n-tuple that has from one to seven components. 藉由使用連續的嵌套層級,您可以建立具有幾乎不限數目之元件的 n 元組。By using successive levels of nesting, you can create an n-tuple that has a virtually unlimited number of components. 例如,若要建立25個元組,您可以具現化具有三個嵌套層級的 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 物件,如下所示:For example, to create a 25-tuple, you instantiate a Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object with three levels of nesting, as follows:

適用於

另請參閱