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
[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
继承
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.

值元组是 @no__t 中引入的元组类型,用于在和中F#的结构元组中 C#提供元组的运行时实现。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.

@No__t-0 结构表示没有元素的元组。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. 通过调用其静态 @no__t 0 方法,你可以创建具有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

在 .NET Core 1.x 或 .NET Framework 4.7 及更早版本中,@no__t 0 类型无法序列化。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)不会强制执行 @no__t 0 实例的序列化;能否序列化 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. 若要确定在特定 .NET 实现上是否可以序列化 @no__t 0 类型,请获取表示 @no__t 类型的 @no__t 1 对象,并检索其 @no__t 属性的值。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)

将当前 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.

适用于