ValueTuple 结构

定义

提供用于创建值元组的静态方法。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
public value class ValueTuple : IComparable, IComparable<ValueTuple>, IEquatable<ValueTuple>, System::Collections::IStructuralComparable, System::Collections::IStructuralEquatable
public struct ValueTuple : IComparable, IComparable<ValueTuple>, IEquatable<ValueTuple>, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable, System.Runtime.CompilerServices.ITuple
public struct ValueTuple : IComparable, IComparable<ValueTuple>, IEquatable<ValueTuple>, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable
[System.Serializable]
public struct ValueTuple : IComparable, IComparable<ValueTuple>, IEquatable<ValueTuple>, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable
type ValueTuple = struct
    interface ITuple
type ValueTuple = struct
[<System.Serializable>]
type ValueTuple = struct
    interface ITuple
Public Structure ValueTuple
Implements IComparable, IComparable(Of ValueTuple), IEquatable(Of ValueTuple), IStructuralComparable, IStructuralEquatable, ITuple
Public Structure ValueTuple
Implements IComparable, IComparable(Of ValueTuple), IEquatable(Of ValueTuple), IStructuralComparable, IStructuralEquatable
继承
ValueTuple
属性
实现

注解

元组是具有特定数量和元素序列的数据结构。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.

  • 它们的数据成员(例如 Item1 、等) Item2 是字段而不是属性。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 方法,你可以创建具有0到8个组件的值元组。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 类型并检索其属性的值 IsSerializableTo 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)

将当前 ValueTuple 实例与指定的 ValueTuple 实例进行比较。Compares the current ValueTuple instance to a specified ValueTuple instance.

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)

创建含有 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)

创建含有 7 个组件的新值元组(七元组)。Creates a new value tuple with 7 components (a septuple).

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)

创建含有 5 个组件的新值元组(五元组)。Creates a new value tuple with 5 components (a quintuple).

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)

创建含有 3 个组件的新值元组(三元组)。Creates a new value tuple with 3 components (a triple).

Create<T1,T2>(T1, T2)

创建含有 2 个组件的新值元组(二元组)。Creates a new value tuple with 2 components (a pair).

Create<T1>(T1)

创建含有 1 个组件的新值元组(一元组)。Creates a new value tuple with 1 component (a singleton).

Equals(Object)

返回一个值,该值指示当前 ValueTuple 实例是否与指定的对象相等。Returns a value that indicates whether the current ValueTuple instance is equal to a specified object.

Equals(ValueTuple)

确定两个 ValueTuple 实例是否相等。Determines whether two ValueTuple instances are equal. 此方法始终返回 trueThis method always returns true.

GetHashCode()

返回当前 ValueTuple 实例的哈希代码。Returns the hash code for the current ValueTuple instance.

ToString()

返回此 ValueTuple 实例的字符串表示形式。Returns the string representation of this ValueTuple instance.

显式接口实现

IComparable.CompareTo(Object)

将此 ValueTuple 实例与指定对象进行比较并返回一个对二者的相对值的指示。Compares this ValueTuple instance with a specified object and returns an indication of their relative values.

IStructuralComparable.CompareTo(Object, IComparer)

将当前 ValueTuple 实例与指定的对象进行比较。Compares the current ValueTuple instance to a specified object.

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)

返回此 ValueTuple 实例的哈希代码。Returns the hash code for this ValueTuple instance.

ITuple.Item[Int32]

返回 IndexOutOfRangeExceptionReturns an IndexOutOfRangeException. ValueTuple 中没有任何元素。There are no elements in a ValueTuple.

ITuple.Length

获取此 ValueTuple 实例的长度,该长度始终为 0。Gets the length of this ValueTuple instance, which is always 0. ValueTuple 中没有任何元素。There are no elements in a ValueTuple.

适用于