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

組の 1 番目のコンポーネントの値。

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> アクセスを提供します。

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

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

適用対象

こちらもご覧ください