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

定义

表示 n 元组,n 为 8 或更大值。Represents an n-tuple, where n is 8 or greater.

generic <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename TRest>
public ref class Tuple : IComparable, System::Collections::IStructuralComparable, System::Collections::IStructuralEquatable
[System.Serializable]
public class Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> : IComparable, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable
type Tuple<'T1, 'T2, 'T3, 'T4, 'T5, 'T6, 'T7, 'Rest> = class
    interface IStructuralEquatable
    interface IStructuralComparable
    interface IComparable
Public Class Tuple(Of T1, T2, T3, T4, T5, T6, T7, TRest)
Implements IComparable, IStructuralComparable, IStructuralEquatable

类型参数

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

任何常规 Tuple 对象,用于定义元组的剩余分量的类型。Any generic Tuple object that defines the types of the tuple's remaining components.

继承
Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>
属性
实现

注解

元组是具有特定数量和值序列的数据结构。A tuple is a data structure that has a specific number and sequence of values. Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>类表示n元组具有八个或多个组件。The Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> class represents an n-tuple that has eight or more components.

可以实例化Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>具有完全八个组件通过调用静态对象Tuple.Create方法。You can instantiate a Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object with exactly eight components by calling the static Tuple.Create method. 以下示例创建一个 8 元组 (八元组) 包含小于 20 的质数。The following example creates an 8-tuple (octuple) that contains prime numbers that are less than 20. 请注意,它使用类型推理来确定每个组件的类型。Note that it uses type inference to determine the type of each component.

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

此外可以实例具有 8 个或多个组件的 n 元组对象化通过调用Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>构造函数。You can also instantiate an n-tuple object with eight or more components by calling the Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> constructor. 下面的示例使用Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>构造函数创建一个 8 元组,它等效于在上一示例中创建的元组。The following example uses the Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> constructor to create an 8-tuple that is equivalent to the tuple created in the previous example.

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

备注

若要创建具有九个或多个组件的 n 元组,必须调用Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>构造函数。To create an n-tuple with nine or more components, you must call the Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> constructor. 静态工厂方法Tuple类不支持创建Tuple具有超过八个组件的对象。The static factory methods of the Tuple class do not support the creation of Tuple objects with more than eight components.

若要实例化 n 元组具有八个或多个组件与Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>构造函数中,提供泛型Tuple对象作为rest参数来定义通过第八个n个组件的元组。To instantiate an n-tuple that has eight or more components with the Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> constructor, you supply a generic Tuple object as the rest parameter to define the eighth through nth components of the tuple. 通过嵌套泛型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.

以下示例创建包含密歇根州底特律每个国家/地区人口普查从 1860 年到 2000年的人口数据的 17-元组。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. 17-元组创建的嵌套Tuple<T1,T2,T3>对象内Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>对象。The 17-tuple is created by nesting a Tuple<T1,T2,T3> object inside a Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object. (这就是,则Tuple<T1,T2,T3>对象提供的值作为rest中的参数Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>类构造函数。)这Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>对象,反过来,嵌套在外部Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>对象。(That is, the Tuple<T1,T2,T3> object is supplied as the value of the rest parameter in the Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> class constructor.) This Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object is, in turn, nested in an outer Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object. (这就是,则Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>对象提供的值作为rest中的外部参数Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>对象的类构造函数。)(That is, the Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object is supplied as the value of the rest parameter in the outer Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object's class constructor.)

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)

您可以使用只读的检索元组的前七个组件的值Item1Item2Item3Item4Item5Item6,和Item7实例属性。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. 任何其他组件嵌套的并且可以从检索Rest属性。Any additional components are nested and can be retrieved from the Rest property. 在上一示例中,Item1通过Item7属性可以检索通过第 7 个组件的元组的第一个。In the previous example, the Item1 through Item7 properties retrieve the first through seventh components of the tuple. 通过第 14 个组件的第 8 个嵌套在第二个级别的元组中包含和由Rest.Item1通过Rest.Item7属性。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. 第十五个到十七个组件包含在嵌套在第三个级别的元组,并且由Rest.Rest.Item1尽管Rest.Rest.Item3属性。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.

  • 若要从无需使用方法返回多个值out参数 (在 C#) 或ByRef参数 (在 Visual Basic 中)。To return multiple values from a method without the use of out parameters (in C#) or ByRef parameters (in Visual Basic). 例如,前面的示例返回城市名称,其计算统计信息中Tuple<T1,T2,T3,T4,T5,T6,T7>对象。For example, the previous example returns its computed statistics, along with the city name, in a Tuple<T1,T2,T3,T4,T5,T6,T7> object.

  • 若要将多个值传递给通过单个参数的方法。To pass multiple values to a method through a single parameter. 例如,Thread.Start(Object)方法只有一个参数,可提供一个值,则该线程在启动时执行的方法。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. 如果提供Tuple<T1,T2,T3,T4,T5,T6,T7>对象作为方法自变量,则可以提供具有七个项数据的线程的启动例程。If you supply a Tuple<T1,T2,T3,T4,T5,T6,T7> object as the method argument, you can supply the thread's startup routine with seven items of data.

构造函数

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>(T1, T2, T3, T4, T5, T6, T7, TRest) 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>(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.

属性

Item1 Item1 Item1 Item1

获取当前 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 对象的第一个分量的值。Gets the value of the current Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object's first component.

Item2 Item2 Item2 Item2

获取当前 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 对象的第二个分量的值。Gets the value of the current Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object's second component.

Item3 Item3 Item3 Item3

获取当前 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 对象的第三个分量的值。Gets the value of the current Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object's third component.

Item4 Item4 Item4 Item4

获取当前 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 对象的第四个分量的值。Gets the value of the current Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object's fourth component.

Item5 Item5 Item5 Item5

获取当前 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 对象的第五个分量的值。Gets the value of the current Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object's fifth component.

Item6 Item6 Item6 Item6

获取当前 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 对象的第六个分量的值。Gets the value of the current Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object's sixth component.

Item7 Item7 Item7 Item7

获取当前 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 对象的第七个分量的值。Gets the value of the current Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object's seventh component.

Rest Rest Rest Rest

获取当前 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 对象的剩余分量。Gets the current Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object's remaining components.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

返回一个值,该值指示当前的 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 对象是否与指定对象相等。Returns a value that indicates whether the current Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object is equal to a specified object.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

计算当前 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 对象的哈希代码。Calculates the hash code for the current Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object.

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示此 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 实例的值的字符串。Returns a string that represents the value of this Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> instance.

显式界面实现

IComparable.CompareTo(Object) IComparable.CompareTo(Object) IComparable.CompareTo(Object) IComparable.CompareTo(Object)

比较当前 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 对象与指定对象,并返回一个整数,该整数指示当前对象在排序顺序中的位置:是在指定对象之前、之后还是在与指定对象相同的位置。Compares the current Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object to a specified object and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order.

IStructuralComparable.CompareTo(Object, IComparer) IStructuralComparable.CompareTo(Object, IComparer) IStructuralComparable.CompareTo(Object, IComparer) IStructuralComparable.CompareTo(Object, IComparer)

使用指定的比较器将当前的 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 对象与指定对象进行比较,并返回一个整数,该整数指示当前对象在排序顺序中的位置是在指定对象之前、之后还是与其相同。Compares the current Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order.

IStructuralEquatable.Equals(Object, IEqualityComparer) IStructuralEquatable.Equals(Object, IEqualityComparer) IStructuralEquatable.Equals(Object, IEqualityComparer) IStructuralEquatable.Equals(Object, IEqualityComparer)

返回一个值,该值根据指定的比较方法指示当前的 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 对象是否与指定对象相等。Returns a value that indicates whether the current Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object is equal to a specified object based on a specified comparison method.

IStructuralEquatable.GetHashCode(IEqualityComparer) IStructuralEquatable.GetHashCode(IEqualityComparer) IStructuralEquatable.GetHashCode(IEqualityComparer) IStructuralEquatable.GetHashCode(IEqualityComparer)

使用指定的计算方法计算当前 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> 对象的哈希代码。Calculates the hash code for the current Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> object by using a specified computation method.

ITuple.Item[Int32] ITuple.Item[Int32] ITuple.Item[Int32] ITuple.Item[Int32]

获取指定 Tuple 元素的值。Gets the value of the specified Tuple element.

ITuple.Length ITuple.Length ITuple.Length ITuple.Length

获取 Tuple 中的元素数。Gets the number of elements in the Tuple.

适用于

另请参阅