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-Tuple,其中 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

Tuple 第 1 個元件的型別。The type of the tuple's first component.

T2

Tuple 第 2 個元件的型別。The type of the tuple's second component.

T3

Tuple 第 3 個元件的型別。The type of the tuple's third component.

T4

Tuple 第 4 個元件的型別。The type of the tuple's fourth component.

T5

Tuple 第 5 個元件的型別。The type of the tuple's fifth component.

T6

Tuple 第 6 個元件的型別。The type of the tuple's sixth component.

T7

Tuple 第 7 個元件的型別。The type of the tuple's seventh component.

TRest

定義 Tuple 其餘元件的類型的任何泛型 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. 類別代表具有8個或多個元件的 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元組 (octuple), 其中包含小於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類別的靜態 factory 方法不支援Tuple建立具有8個以上元件的物件。The static factory methods of the Tuple class do not support the creation of Tuple objects with more than eight components.

若要具現化具有8個或更多元件與此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)。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. 每個後續元件都會提供10年間隔的人口。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> 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.Item1Rest.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 by 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 的淺層複本 (Shallow Copy)。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.

適用於

另請參閱