ValueTuple ValueTuple ValueTuple ValueTuple Struct

定義

提供用於建立值元組的靜態方法。Provides static methods for creating value tuples.

public value class ValueTuple : IComparable, IComparable<ValueTuple>, IEquatable<ValueTuple>, System::Collections::IStructuralComparable, System::Collections::IStructuralEquatable, System::Runtime::CompilerServices::ITuple
[System.Serializable]
public struct ValueTuple : IComparable, IComparable<ValueTuple>, IEquatable<ValueTuple>, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable, System.Runtime.CompilerServices.ITuple
type ValueTuple = struct
    interface ITuple
Public Structure ValueTuple
Implements IComparable, IComparable(Of ValueTuple), IEquatable(Of ValueTuple), IStructuralComparable, IStructuralEquatable, ITuple
繼承
ValueTupleValueTupleValueTupleValueTuple
屬性
實作

備註

元組是一種資料結構, 具有特定數目和專案序列。A tuple is a data structure that has a specific number and sequence of elements. 元組的範例是一個資料結構, 其中包含三個元素 (也稱為3元組或三層), 用來儲存識別碼, 例如第一個元素中的人員名稱、第二個元素中的年份, 以及第三個元素中該年份的個人收入。An example of a tuple is a data structure with three elements (known as a 3-tuple or triple) that is used to store an identifier such as a person's name in the first element, a year in the second element, and the person's income for that year in the third element.

值元組是中引進的.NET Framework 4.7.NET Framework 4.7元組類型, 可在中提供元C# 組的執行時間執行和中F#的結構元組。Value tuples are tuple types introduced in the .NET Framework 4.7.NET Framework 4.7 to provide the runtime implementation of tuples in C# and struct tuples in F#. 它們不同于元組類別, 例如Tuple<T1>Tuple<T1,T2>等等, 如下所示:They differ from the tuple classes, such as Tuple<T1>, Tuple<T1,T2>, etc., as follows:

  • 它們是結構 (實數值型別), 而不是類別 (參考類型)。They are structures (value types) rather than classes (reference types).

  • 它們是可變動的, 而不是唯讀的。They are mutable rather than read-only. 也就是, 元組元件的值可能會變更。That is, the value of tuple components can change.

  • 其資料成員 (例如Item1Item2等) 是欄位, 而不是屬性。Their data members, such as Item1, Item2, etc., are fields rather than properties.

ValueTuple結構代表沒有任何元素的元組。The ValueTuple structure represents a tuple that has no elements. 它主要適用于其靜態方法, 可讓您建立和比較值元組類型的實例。It is useful primarily for its static methods that let you create and compare instances of value tuple types. 其 helper 方法可讓您具現化值元組, 而不需要明確指定每個值元組元件的類型。Its helper methods let you instantiate value tuples without having to explicitly specify the type of each value tuple component. 藉由呼叫其Create靜態方法, 您可以建立具有零到八個元件的值元組。By calling its static Create methods, you can create value tuples that have from zero to eight components. 針對具有8個以上元件的值元組, 您必須ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest>呼叫此函式。For value tuples with more than eight components, you must call the ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest> constructor.

序列化和值元組Serialization and value tuples

ValueTuple .net Core 1.x 或 .NET Framework 4.7 和更早版本中, 類型不可序列化。The ValueTuple type is not serializable in .NET Core 1.x or in the .NET Framework 4.7 and earlier versions. 此外, .NET Standard (包括 .NET Standard 2.0) 不會強制執行實例的ValueTuple序列化; 不論ValueTuple實例是否可序列化, 都取決於個別的 .NET Standard 執行。In addition, .NET Standard, including .NET Standard 2.0, does not mandate serialization of ValueTuple instances; whether or not a ValueTuple instance is serializable depends on the individual .NET Standard implementation. 若要判斷ValueTuple類型是否可在特定的 .net 執行上序列化, 請Type取得代表ValueTuple類型的物件, 並取出其IsSerializable屬性的值。To determine whether a ValueTuple type is serializable on a particular .NET implementation, get a Type object that represents the ValueTuple type and retrieve the value of its IsSerializable property. 如需 .NET Core 和 .NET Framework 中的可序列化類型清單, 請參閱二進位序列化For a list of serializable types in .NET Core and the .NET Framework, see Binary Serialization.

方法

CompareTo(ValueTuple) CompareTo(ValueTuple) CompareTo(ValueTuple) CompareTo(ValueTuple)

比較目前的 ValueTuple 執行個體與指定的 ValueTuple 執行個體。Compares the current ValueTuple instance to a specified ValueTuple instance.

Create() Create() Create() Create()

建立不含元件的新值元組。Creates a new value tuple with zero components.

Create<T1,T2,T3,T4,T5,T6,T7,T8>(T1, T2, T3, T4, T5, T6, T7, T8) Create<T1,T2,T3,T4,T5,T6,T7,T8>(T1, T2, T3, T4, T5, T6, T7, T8) Create<T1,T2,T3,T4,T5,T6,T7,T8>(T1, T2, T3, T4, T5, T6, T7, T8) Create<T1,T2,T3,T4,T5,T6,T7,T8>(T1, T2, T3, T4, T5, T6, T7, T8)

建立含有 8 個元件的新值元組 (八重物件)。Creates a new value tuple with 8 components (an octuple).

Create<T1,T2,T3,T4,T5,T6,T7>(T1, T2, T3, T4, T5, T6, T7) Create<T1,T2,T3,T4,T5,T6,T7>(T1, T2, T3, T4, T5, T6, T7) Create<T1,T2,T3,T4,T5,T6,T7>(T1, T2, T3, T4, T5, T6, T7) Create<T1,T2,T3,T4,T5,T6,T7>(T1, T2, T3, T4, T5, T6, T7)

建立含有 7 個元件的新值元組 (七重物件)。Creates a new value tuple with 7 components (a septuple).

Create<T1,T2,T3,T4,T5,T6>(T1, T2, T3, T4, T5, T6) Create<T1,T2,T3,T4,T5,T6>(T1, T2, T3, T4, T5, T6) Create<T1,T2,T3,T4,T5,T6>(T1, T2, T3, T4, T5, T6) Create<T1,T2,T3,T4,T5,T6>(T1, T2, T3, T4, T5, T6)

建立含有 6 個元件的新值元組 (六重物件)。Creates a new value tuple with 6 components (a sexuple).

Create<T1,T2,T3,T4,T5>(T1, T2, T3, T4, T5) Create<T1,T2,T3,T4,T5>(T1, T2, T3, T4, T5) Create<T1,T2,T3,T4,T5>(T1, T2, T3, T4, T5) Create<T1,T2,T3,T4,T5>(T1, T2, T3, T4, T5)

建立含有 5 個元件的新值元組 (五重物件)。Creates a new value tuple with 5 components (a quintuple).

Create<T1,T2,T3,T4>(T1, T2, T3, T4) Create<T1,T2,T3,T4>(T1, T2, T3, T4) Create<T1,T2,T3,T4>(T1, T2, T3, T4) Create<T1,T2,T3,T4>(T1, T2, T3, T4)

建立含有 4 個元件的新值元組 (四重物件)。Creates a new value tuple with 4 components (a quadruple).

Create<T1,T2,T3>(T1, T2, T3) Create<T1,T2,T3>(T1, T2, T3) Create<T1,T2,T3>(T1, T2, T3) Create<T1,T2,T3>(T1, T2, T3)

建立含有 3 個元件的新值元組 (三重物件)。Creates a new value tuple with 3 components (a triple).

Create<T1,T2>(T1, T2) Create<T1,T2>(T1, T2) Create<T1,T2>(T1, T2) Create<T1,T2>(T1, T2)

建立含有 2 個元件的新值元組 (一對)。Creates a new value tuple with 2 components (a pair).

Create<T1>(T1) Create<T1>(T1) Create<T1>(T1) Create<T1>(T1)

建立含有 1 個元件的新值元組 (單一物件)。Creates a new value tuple with 1 component (a singleton).

Equals(ValueTuple) Equals(ValueTuple) Equals(ValueTuple) Equals(ValueTuple)

判斷兩個 ValueTuple 執行個體是否相等。Determines whether two ValueTuple instances are equal. 這個方法一律會傳回 trueThis method always returns true.

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

傳回值,這個值指出目前的 ValueTuple 執行個體是否與指定的物件相等。Returns a value that indicates whether the current ValueTuple instance is equal to a specified object.

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

傳回目前 ValueTuple 執行個體的雜湊碼。Returns the hash code for the current ValueTuple instance.

ToString() ToString() ToString() ToString()

傳回這個 ValueTuple 執行個體的字串表示。Returns the string representation of this ValueTuple instance.

明確介面實作

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

將目前的 ValueTuple 執行個體與指定的物件相比較。Compares the current ValueTuple instance to a specified object.

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

傳回值,這個值會根據指定的比較方法,指出目前的 ValueTuple 執行個體是否與指定的物件相等。Returns a value that indicates whether the current ValueTuple instance is equal to a specified object based on a specified comparison method.

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

傳回這個 ValueTuple 執行個體的雜湊碼。Returns the hash code for this ValueTuple instance.

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

將這個 ValueTuple 執行個體與指定的物件相比較,並傳回其相對值的指示。Compares this ValueTuple instance with a specified object and returns an indication of their relative values.

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

傳回 IndexOutOfRangeExceptionReturns an IndexOutOfRangeException. ValueTuple 中沒有項目。There are no elements in a ValueTuple.

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

取得此 ValueTuple 執行個體的長度,其一律為 0。Gets the length of this ValueTuple instance, which is always 0. ValueTuple 中沒有項目。There are no elements in a ValueTuple.

適用於