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. 类表示具有八个或更多组件的 n 元组。 Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>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

还可以通过调用Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>构造函数, 实例化包含八个或更多组件的 n 元组对象。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创建具有超过8个组件的对象。The static factory methods of the Tuple class do not support the creation of Tuple objects with more than eight components.

Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>要使用构造函数实例化包含八个或更多组件的 n 元组, 请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.

下面的示例创建一个17元组, 该元组包含每个美国人口普查1860到2000的 Detroit 的人口数据。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. 通过在Tuple<T1,T2,T3> Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>对象中嵌套对象来创建17元组。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>将对象作为Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>类构造函数中的rest参数值提供。)此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>将对象作为外部Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>对象的类构造函数中rest的参数值提供。)(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)

Item1可以使用只读、 Item2Item3Item4 Item5 、、Item7和实例属性检索元组的前七个组件的值。 Item6You 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属性检索元组的第一个到第七个组件。In the previous example, the Item1 through Item7 properties retrieve the first through seventh components of the tuple. 第八个到第十四个组件包含在嵌套在第二级的元组中, 由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. 第十五到第17个组件包含在嵌套于第三级的元组中, 并由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.

适用于

另请参阅