ValueTuple
ValueTuple
ValueTuple
ValueTuple
Struct
Definition
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
- Inheritance
- Attributes
- Implements
Remarks
A tuple is a data structure that has a specific number and sequence of elements. 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.
Value tuples are tuple types introduced in the .NET Framework 4.7 to provide the runtime implementation of tuples in C# and struct tuples in F#. 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.
Their data members, such as
Item1
,Item2
, etc., are fields rather than properties.
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. By calling its static Create methods, you can create value tuples that have from zero to eight components. 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
The ValueTuple type is not serializable in .NET Core 1.x or in the .NET Framework 4.7 and earlier versions. 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. 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. For a list of serializable types in .NET Core and the .NET Framework, see Binary Serialization.
Methods
Explicit Interface Implementations
Applies to
Feedback
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.
Loading feedback...