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.Serializable]
public struct ValueTuple : IComparable, IComparable<ValueTuple>, IEquatable<ValueTuple>, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable
type ValueTuple = struct
Public Structure ValueTuple
Implements IComparable, IComparable(Of ValueTuple), IEquatable(Of ValueTuple), IStructuralComparable, IStructuralEquatable
继承
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. 及其帮助程序方法,可以实例化值元组,而无需显式指定每个值元组组件的类型。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.

序列化和值元组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.

适用于