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<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.

值元组类型提供支持的运行时实现中的元组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)工厂方法。In addition to creating a ValueTuple<T1> instance by using language syntax, you can call the ValueTuple.Create<T1>(T1) factory method.

序列化和值元组Serialization 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> 实例的第 1 个元素的值。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.

适用于