次の方法で共有


Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> コンストラクター

定義

Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> クラスの新しいインスタンスを初期化します。

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

タプルの最初のコンポーネントの値。

item2
T2

タプルの 2 番目のコンポーネントの値。

item3
T3

タプルの 3 番目のコンポーネントの値。

item4
T4

タプルの 4 番目のコンポーネントの値。

item5
T5

タプルの 5 番目のコンポーネントの値。

item6
T6

タプルの 6 番目のコンポーネントの値。

item7
T7

タプルの 7 番目のコンポーネントの値。

rest
TRest

タプルの残りのコンポーネントの値を含むジェネリック Tuple オブジェクト。

例外

rest はジェネリック Tuple オブジェクトではありません。

次の例では、1860 年から 2000 年までの国勢調査ごとに、ミシガン州デトロイト市の人口データを含む 17 タプルを作成します。 タプルの最初のコンポーネントは、市区町村の名前です。 2 番目のコンポーネントは一連のデータの開始日であり、3 番目のコンポーネントは開始日の母集団です。 後続の各コンポーネントは、10 年間隔で母集団を提供します。 この例では、2 つの入れ子レイヤーを使用して 17 タプルを作成します。3 番目から 7 番目のコンポーネントに 1860 から 1900 の母集団データが含まれる 7 タプル、1910 から 1970 の母集団データを含む入れ子になった 7 タプル、1980 から 2000 の母集団データを含む内部の入れ子になった 3 タプルが定義されています。

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);
let from1980 = Tuple.Create(1203339, 1027974, 951270)
let from1910 = new Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>(465766, 993078, 1568622, 1623452, 1849568, 1670144, 1511462, from1980)
let 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) オブジェクトをインスタンス化することもできます。 次の例では、 Tuple.Create メソッドを使用して、20 未満の素数を含む 8 タプル オブジェクトをインスタンス化します。

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
open System

let primes = Tuple.Create(2, 3, 5, 7, 11, 13, 17, 19)
printfn $"Prime numbers less than 20: {primes.Item1}, {primes.Item2}, {primes.Item3}, {primes.Item4}, {primes.Item5}, {primes.Item6}, {primes.Item7}, and {primes.Rest.Item1}"
//    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> クラス コンストラクターに対する次の呼び出しと同じです。

var primes = new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32,  
             Tuple<Int32>> (2, 3, 5, 7, 11, 13, 17, new Tuple<Int32>(19));
let 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 つを超えるコンポーネントを含むタプル オブジェクトを作成することはできません。

Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> コンストラクターを使用して 8 つ以上のコンポーネントを含む n タプルを作成する場合は、rest パラメーターを使用して、1 から 7 個のコンポーネントを含む入れ子になった n タプルを作成します。 連続するレベルの入れ子を使用すると、実質的に無制限の数のコンポーネントを持つ n タプルを作成できます。 たとえば、25 タプルを作成するには、次のように 3 つのレベルの入れ子を持つ Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> オブジェクトをインスタンス化します。

  • 最も外側の Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> オブジェクトには、最初から 7 番目のコンポーネントが含まれます。 その Rest プロパティは、入れ子の最初のレベルで Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> オブジェクトへのアクセスを提供します。

  • 最も外側の入れ子になった Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> オブジェクトには 8 番目から 14 番目のコンポーネントが含まれており、その Rest プロパティは、入れ子の 2 番目のレベルで Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> オブジェクトにアクセスできます。

  • 入れ子の 2 番目のレベルの Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> オブジェクトには、15 番目から 20 番目のコンポーネントが含まれており、その Rest プロパティは、入れ子の 3 番目のレベルで Tuple<T1,T2,T3,T4> オブジェクトへのアクセスを提供します。

  • 最も内側のタプルは、20 秒から 25 番目のコンポーネントを含む Tuple<T1,T2,T3,T4> オブジェクトです。

適用対象

こちらもご覧ください