ValueTuple<T1> ValueTuple<T1> ValueTuple<T1> ValueTuple<T1> Struct

定義

表示含有單一元件的值元組。Represents a value tuple with a single component.

generic <typename T1>
public value class ValueTuple : IComparable, IComparable<ValueTuple<T1>>, IEquatable<ValueTuple<T1>>, System::Collections::IStructuralComparable, System::Collections::IStructuralEquatable, System::Runtime::CompilerServices::ITuple
[System.Serializable]
public struct ValueTuple<T1> : IComparable, IComparable<ValueTuple<T1>>, IEquatable<ValueTuple<T1>>, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable, System.Runtime.CompilerServices.ITuple
type ValueTuple<'T1> = struct
    interface ITuple
Public Structure ValueTuple(Of T1)
Implements IComparable, IComparable(Of ValueTuple(Of T1)), IEquatable(Of ValueTuple(Of T1)), IStructuralComparable, IStructuralEquatable, ITuple

類型參數

T1

值元組唯一元素的類型。The type of the value tuple's only element.

繼承
ValueTuple<T1>ValueTuple<T1>ValueTuple<T1>ValueTuple<T1>
屬性
實作

備註

值元組是具有特定的數字和值序列的資料結構。A value tuple is a data structure that has a specific number and sequence of values. ValueTuple<T1>結構是表示有一個元素的值元組。The ValueTuple<T1> structure represents a value tuple that has one element.

值元組類型不同的 tuple 型別 (例如Tuple<T1>,如下所示:The value tuple types differ from the tuple types (such as Tuple<T1> as follows:

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

  • Item1成員是欄位,而不是屬性。Its Item1 member is a field rather than a property.

  • 其欄位是可變動而非唯讀狀態。Its field is mutable rather than read-only.

值元組類型提供支援的執行階段實作tuple C# 中的結構元組和F#。The value tuple types provide the runtime implementation that supports tuples in C# and struct tuples in F#. 除了建立ValueTuple<T1>執行個體所使用的語言語法,您可以呼叫ValueTuple.Create<T1>(T1)factory 方法。In addition to creating a ValueTuple<T1> instance by using language syntax, you can call the ValueTuple.Create<T1>(T1) factory method.

序列化和值的 tupleSerialization and value tuples

ValueTuple<T1>類型不是可序列化的.NET Core 1.x 或在.NET Framework 4.7 和舊版本。The ValueTuple<T1> 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<T1>執行個體; 是否ValueTuple<T1>是可序列化的執行個體取決於個別的.NET Standard 實作。In addition, .NET Standard, including .NET Standard 2.0, does not mandate serialization of ValueTuple<T1> instances; whether or not a ValueTuple<T1> instance is serializable depends on the individual .NET Standard implementation. 若要判斷是否ValueTuple<T1>型別是可序列化特定的.NET 實作上,會取得Type物件,表示ValueTuple<T1>類型及擷取的值及其IsSerializable屬性。To determine whether a ValueTuple<T1> type is serializable on a particular .NET implementation, get a Type object that represents the ValueTuple<T1> 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.

建構函式

ValueTuple<T1>(T1) ValueTuple<T1>(T1) ValueTuple<T1>(T1) ValueTuple<T1>(T1)

初始化新的 ValueTuple<T1> 執行個體。Initializes a new ValueTuple<T1> instance.

欄位

Item1 Item1 Item1 Item1

取得目前 ValueTuple<T1> 執行個體第一個元素的值。Gets the value of the current ValueTuple<T1> instance's first element.

方法

CompareTo(ValueTuple<T1>) CompareTo(ValueTuple<T1>) CompareTo(ValueTuple<T1>) CompareTo(ValueTuple<T1>)

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

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

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

Equals(ValueTuple<T1>) Equals(ValueTuple<T1>) Equals(ValueTuple<T1>) Equals(ValueTuple<T1>)

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

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

計算目前 ValueTuple<T1> 執行個體的雜湊碼。Calculates the hash code for the current ValueTuple<T1> instance.

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

傳回字串,表示這個 ValueTuple<T1> 執行個體的值。Returns a string that represents the value of this ValueTuple<T1> instance.

明確介面實作

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

使用指定的比較子來比較目前的 ValueTuple<T1> 執行個體與指定的物件,並傳回一個整數,指出目前的物件在排序次序中,是位於指定物件之前、之後或相同的位置。Compares the current ValueTuple<T1> instance 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)

傳回值,這個值會根據指定的比較方法,指出目前的 ValueTuple<T1> 執行個體是否與指定的物件相等。Returns a value that indicates whether the current ValueTuple<T1> 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<T1> 執行個體的雜湊碼。Calculates the hash code for the current ValueTuple<T1> instance by using a specified computation method.

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

使用指定的比較子來比較目前的 ValueTuple<T1> 執行個體與指定的物件,並傳回一個整數,指出目前的物件在排序次序中,是位於指定物件之前、之後或相同的位置。Compares the current ValueTuple<T1> instance 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.

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

取得 ValueTuple 項目值。Gets the value of the ValueTuple element.

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

取得 ValueTuple 中的項目數目。Gets the number of elements in the ValueTuple.

Extension Methods

ToTuple<T1>(ValueTuple<T1>) ToTuple<T1>(ValueTuple<T1>) ToTuple<T1>(ValueTuple<T1>) ToTuple<T1>(ValueTuple<T1>)

ValueTuple 結構的執行個體轉換為 Tuple 類別的執行個體。Converts an instance of the ValueTuple structure to an instance of the Tuple class.

適用於