Aracılığıyla paylaş


Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> Constructor

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Initializes a new instance of the Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> class.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
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 _
)
public Tuple(
    T1 item1,
    T2 item2,
    T3 item3,
    T4 item4,
    T5 item5,
    T6 item6,
    T7 item7,
    TRest rest
)

Parameters

  • item1
    Type: T1
    The value of the tuple's first component.
  • item2
    Type: T2
    The value of the tuple's second component.
  • item3
    Type: T3
    The value of the tuple's third component.
  • item4
    Type: T4
    The value of the tuple's fourth component
  • item5
    Type: T5
    The value of the tuple's fifth component.
  • item6
    Type: T6
    The value of the tuple's sixth component.
  • item7
    Type: T7
    The value of the tuple's seventh component.
  • rest
    Type: TRest
    Any generic Tuple object that contains the values of the tuple's remaining components.

Exceptions

Exception Condition
ArgumentException

rest is not a generic Tuple object.

Remarks

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. The following example uses the Tuple.Create method to instantiate an 8-tuple object that contains prime numbers that are less than 20.

Dim primes = Tuple.Create(2, 3, 5, 7, 11, 13, 17, 19)
var primes = Tuple.Create(2, 3, 5, 7, 11, 13, 17, 19);

This is equivalent to the following call to the Tuple<T1, T2, T3, T4, T5, T6, T7> class constructor.

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))
var primes = new Tuple<Int32, Int32, Int32, Int32, Int32, Int32, Int32,
             Tuple<Int32>>(2, 3, 5, 7, 11, 13, 17, new Tuple<Int32>(19));

However, the static Tuple.Create method cannot be used to create a tuple object with more than eight components.

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. By using successive levels of nesting, you can create an n-tuple that has a virtually unlimited number of components. 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:

Examples

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. Each subsequent component provides the population at decade intervals. 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.

outputBlock.FontFamily = New System.Windows.Media.FontFamily("Courier New")

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)
outputBlock.FontFamily = new System.Windows.Media.FontFamily("Courier New");

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);

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.