Tuple Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents an n-tuple, where n is 8 or greater.
generic
public ref class Tuple : IComparable, System::Collections::IStructuralComparable, System::Collections::IStructuralEquatable
generic
public ref class Tuple : IComparable, System::Collections::IStructuralComparable, System::Collections::IStructuralEquatable, System::Runtime::CompilerServices::ITuple
public class Tuple : IComparable, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable
public class Tuple : IComparable, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable, System.Runtime.CompilerServices.ITuple
[System.Serializable]
public class Tuple : IComparable, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable
type Tuple<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7, 'Rest> = class
interface IStructuralComparable
interface IStructuralEquatable
interface IComparable
type Tuple<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7, 'Rest> = class
interface IStructuralComparable
interface IStructuralEquatable
interface IComparable
interface ITuple
[]
type Tuple<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7, 'Rest> = class
interface IStructuralEquatable
interface IStructuralComparable
interface IComparable
[]
type Tuple<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7, 'Rest> = class
interface IStructuralEquatable
interface IStructuralComparable
interface IComparable
interface ITuple
Public Class Tuple(Of T1, T2, T3, T4, T5, T6, T7, TRest)
Implements IComparable, IStructuralComparable, IStructuralEquatable
Public Class Tuple(Of T1, T2, T3, T4, T5, T6, T7, TRest)
Implements IComparable, IStructuralComparable, IStructuralEquatable, ITuple
Type Parameters
- T1
The type of the tuple's first component.
- T2
The type of the tuple's second component.
- T3
The type of the tuple's third component.
- T4
The type of the tuple's fourth component.
- T5
The type of the tuple's fifth component.
- T6
The type of the tuple's sixth component.
- T7
The type of the tuple's seventh component.
- TRest
Any generic Tuple object that defines the types of the tuple's remaining components.
- Inheritance
-
Tuple
- Attributes
- Implements
Remarks
A tuple is a data structure that has a specific number and sequence of values. The Tuple
You can instantiate a Tuple
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
You can also instantiate an n-tuple object with eight or more components by calling the Tuple
var primes = new Tuple> (2, 3, 5, 7, 11, 13, 17, new Tuple(19));
let primes = new Tuple> (2, 3, 5, 7, 11, 13, 17, new Tuple(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))
Note
To create an n-tuple with nine or more components, you must call the TupleTuple objects with more than eight components.
To instantiate an n-tuple that has eight or more components with the TupleTuple object as the rest parameter to define the eighth through nth components of the tuple. By nesting generic Tuple objects in this way, you can create a tuple that has no practical limitation on the number of its components.
The following example creates a 17-tuple that contains population data for the city of Detroit, Michigan, for each national census from 1860 to 2000. The first component of the tuple is the city name. The second component is the start date of the data series, and the third component is the population at the start date. Each subsequent component provides the population at decade intervals. The 17-tuple is created by nesting a Tuplerest parameter in the Tuplerest parameter in the outer Tuple
var from1980 = Tuple.Create(1203339, 1027974, 951270);
var from1910 = new Tuple>
(465766, 993078, 1568622, 1623452, 1849568, 1670144, 1511462, from1980);
var population = new Tuple>>
("Detroit", 1860, 45619, 79577, 116340, 205876, 285704, from1910);
let from1980 = Tuple.Create(1203339, 1027974, 951270)
let from1910 = new Tuple>(465766, 993078, 1568622, 1623452, 1849568, 1670144, 1511462, from1980)
let population = new Tuple>>("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)
You can retrieve the value of the tuple's first seven components by using the read-only Item1, Item2, Item3, Item4, Item5, Item6, and Item7 instance properties. Any additional components are nested and can be retrieved from the Rest property. In the previous example, the Item1 through Item7 properties retrieve the first through seventh components of the tuple. The eighth through fourteenth components are contained in the tuple that is nested at the second level, and are represented by the Rest.Item1 through Rest.Item7 properties. The fifteenth through seventeenth components are contained in the tuple that is nested at the third level, and are represented by the Rest.Rest.Item1 though Rest.Rest.Item3 properties.
Tuples are commonly used in four different ways:
To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record.
To provide easy access to, and manipulation of, a data set.
To return multiple values from a method without the use of
outparameters (in C#) orByRefparameters (in Visual Basic). For example, the previous example returns its computed statistics, along with the city name, in a Tupleobject. To pass multiple values to a method through a single parameter. For example, the Thread.Start(Object) method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a Tuple
object as the method argument, you can supply the thread's startup routine with seven items of data.
Constructors
| Name | Description |
|---|---|
|
Tuple |
Initializes a new instance of the Tuple |
Properties
| Name | Description |
|---|---|
| Item1 |
Gets the value of the current Tuple |
| Item2 |
Gets the value of the current Tuple |
| Item3 |
Gets the value of the current Tuple |
| Item4 |
Gets the value of the current Tuple |
| Item5 |
Gets the value of the current Tuple |
| Item6 |
Gets the value of the current Tuple |
| Item7 |
Gets the value of the current Tuple |
| Rest |
Gets the current Tuple |
Methods
| Name | Description |
|---|---|
| Equals(Object) |
Returns a value that indicates whether the current Tuple |
| GetHashCode() |
Calculates the hash code for the current Tuple |
| GetType() |
Gets the Type of the current instance. (Inherited from Object) |
| MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
| ToString() |
Returns a string that represents the value of this Tuple |
Explicit Interface Implementations
| Name | Description |
|---|---|
| IComparable.CompareTo(Object) |
Compares the current Tuple |
| IStructuralComparable.CompareTo(Object, IComparer) |
Compares the current Tuple |
| IStructuralEquatable.Equals(Object, IEqualityComparer) |
Returns a value that indicates whether the current Tuple |
| IStructuralEquatable.GetHashCode(IEqualityComparer) |
Calculates the hash code for the current Tuple |
| ITuple.Item[Int32] |
Gets the value of the specified |
| ITuple.Length |
Gets the number of elements in the |