ValueTuple<T1,T2,T3> ValueTuple<T1,T2,T3> ValueTuple<T1,T2,T3> ValueTuple<T1,T2,T3> Struct

定义

表示含有 3 个组件的值元组。Represents a value tuple with 3 components.

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

类型参数

T1

值元组的第 1 个元素的类型。The type of the value tuple's first element.

T2

值元组的第 2 个元素的类型。The type of the value tuple's second element.

T3

值元组的第 3 个元素的类型。The type of the value tuple's third element.

继承
ValueTuple<T1,T2,T3>ValueTuple<T1,T2,T3>ValueTuple<T1,T2,T3>ValueTuple<T1,T2,T3>
属性
实现

注解

值元组是具有特定数量和值序列的数据结构。A value tuple is a data structure that has a specific number and sequence of values. ValueTuple<T1,T2,T3>结构表示具有三个元素的值元组。The ValueTuple<T1,T2,T3> structure represents a value tuple that has three elements.

值元组类型不同于元组类型 (如Tuple<T1,T2,T3>), 如下所示:The value tuple types differ from the tuple types (such as Tuple<T1,T2,T3>) as follows:

  • 它们是结构 (值类型) 而不是类 (引用类型)。They are structures (value types) rather than classes (reference types).

  • 成员 ( Item1例如和Item2 ) 是字段而不是属性。Members such as Item1 and Item2 are fields rather than properties.

  • 它们的字段是可变的, 而不是只读的。Their fields are mutable rather than read-only.

值元组类型提供支持中的元组C# 和中F#的结构元组的运行时实现。The value tuple types provide the runtime implementation that supports tuples in C# and struct tuples in F#. 除了使用语言语法创建ValueTuple<T1,T2,T3>实例外, 还可以Create调用工厂方法。In addition to creating a ValueTuple<T1,T2,T3> instance by using language syntax, you can call the Create factory method.

序列化和值元组Serialization and value tuples

ValueTuple<T1,T2,T3>类型在 .net Core 1.x 或 .NET Framework 4.7 及更早版本中不可序列化。The ValueTuple<T1,T2,T3> 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,T2,T3>实例进行序列化; 是否ValueTuple<T1,T2,T3>可序列化实例取决于单个 .NET Standard 实现。In addition, .NET Standard, including .NET Standard 2.0, does not mandate serialization of ValueTuple<T1,T2,T3> instances; whether or not a ValueTuple<T1,T2,T3> instance is serializable depends on the individual .NET Standard implementation. 若要确定某ValueTuple<T1,T2,T3>一类型在特定 .net 实现上是否可序列化Type , 请获取一个ValueTuple<T1,T2,T3>对象, 该对象表示类型并IsSerializable检索其属性的值。To determine whether a ValueTuple<T1,T2,T3> type is serializable on a particular .NET implementation, get a Type object that represents the ValueTuple<T1,T2,T3> 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,T2,T3>(T1, T2, T3) ValueTuple<T1,T2,T3>(T1, T2, T3) ValueTuple<T1,T2,T3>(T1, T2, T3) ValueTuple<T1,T2,T3>(T1, T2, T3)

初始化一个新 ValueTuple<T1,T2,T3> 实例。Initializes a new ValueTuple<T1,T2,T3> instance.

字段

Item1 Item1 Item1 Item1

获取当前 ValueTuple<T1,T2,T3> 实例的第 1 个元素的值。Gets the value of the current ValueTuple<T1,T2,T3> instance's first element.

Item2 Item2 Item2 Item2

获取当前 ValueTuple<T1,T2,T3> 实例的第 2 个元素的值。Gets the value of the current ValueTuple<T1,T2,T3> instance's second element.

Item3 Item3 Item3 Item3

获取当前 ValueTuple<T1,T2,T3> 实例的第 3 个元素的值。Gets the value of the current ValueTuple<T1,T2,T3> instance's third element.

方法

CompareTo(ValueTuple<T1,T2,T3>) CompareTo(ValueTuple<T1,T2,T3>) CompareTo(ValueTuple<T1,T2,T3>) CompareTo(ValueTuple<T1,T2,T3>)

将当前 ValueTuple<T1,T2,T3> 实例与指定的 ValueTuple<T1,T2,T3> 实例进行比较。Compares the current ValueTuple<T1,T2,T3> instance to a specified ValueTuple<T1,T2,T3> instance.

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

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

Equals(ValueTuple<T1,T2,T3>) Equals(ValueTuple<T1,T2,T3>) Equals(ValueTuple<T1,T2,T3>) Equals(ValueTuple<T1,T2,T3>)

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

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

计算当前 ValueTuple<T1,T2,T3> 实例的哈希代码。Calculates the hash code for the current ValueTuple<T1,T2,T3> instance.

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

返回表示此 ValueTuple<T1,T2,T3> 实例的值的字符串。Returns a string that represents the value of this ValueTuple<T1,T2,T3> instance.

显式界面实现

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

使用指定的比较器比较当前 ValueTuple<T1,T2,T3> 实例与指定对象,并返回一个整数,该整数指示当前对象在排序顺序中的位置:是在指定对象之前、之后还是在与指定对象相同的位置。Compares the current ValueTuple<T1,T2,T3> 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,T2,T3> 实例是否与指定的对象相等。Returns a value that indicates whether the current ValueTuple<T1,T2,T3> 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,T2,T3> 实例的哈希代码。Calculates the hash code for the current ValueTuple<T1,T2,T3> instance by using a specified computation method.

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

使用指定的比较器比较当前 ValueTuple<T1,T2,T3> 实例与指定对象,并返回一个整数,该整数指示当前对象在排序顺序中的位置:是在指定对象之前、之后还是在与指定对象相同的位置。Compares the current ValueTuple<T1,T2,T3> 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 specified ValueTuple element.

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

获取 ValueTuple 中的元素数。Gets the number of elements in the ValueTuple.

扩展方法

ToTuple<T1,T2,T3>(ValueTuple<T1,T2,T3>) ToTuple<T1,T2,T3>(ValueTuple<T1,T2,T3>) ToTuple<T1,T2,T3>(ValueTuple<T1,T2,T3>) ToTuple<T1,T2,T3>(ValueTuple<T1,T2,T3>)

ValueTuple 结构的实例转换为 Tuple 类的实例。Converts an instance of the ValueTuple structure to an instance of the Tuple class.

适用于