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
屬性
實作

備註

Tuple 是有特定數目和項目序列的資料結構。A tuple is a data structure that has a specific number and sequence of elements. Tuple 的範例是用來將某個識別碼,例如連絡人的名稱儲存在第一個項目、 一年中的第二個項目,且該人員的 income 該年份的第三個項目中的資料結構 (又稱為 3-tuple 或三重物件) 的三個項目。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.

值元組是所導入的 tuple 類型.NET Framework 4.7.NET Framework 4.7提供的執行階段實作tuple C# 和結構中的 tuple 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. 也就是 tuple 元件的值可能會變更。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. 及其協助程式方法可讓您將值元組而不需要明確指定每個值元組元件型別執行個體化。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. 超過八個元件的值元組,您必須呼叫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.

序列化和值的 tupleSerialization 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.

適用於