Tuple<T1> Class

System

Represents a value tuple with a single component.

A ValueTuple type is a value type that enables you to create a tuple with a specified number of components without having to define and declare a custom type. Value tuples are lighter-weight than the System.Tuple classes.

Syntax

public struct ValueTuple<T1> : IComparable, IComparable<ValueTuple<T1>>, IEquatable<ValueTuple<T1>>, ITuple

Type Parameters:

T1
The type of the first component of the tuple.

Remarks

The ValueTuple<T1> struct is the runtime representation of a tuple with a single element. It is used internally by the .NET runtime for tuples defined with the value tuple syntax (e.g., (int item1)).

This struct provides efficient storage and access to its single component.

Constructors

  • ValueTuple<T1> (T1 item1) public ValueTuple<T1>(T1 item1)

    Initializes a new instance of the ValueTuple<T1> struct by assigning a value to the tuple's single element.

Fields

  • Item1 public T1 Item1

    Gets the value of the first element of the tuple.

Methods

  • CompareTo (ValueTuple<T1> other) public int CompareTo(ValueTuple<T1> other)

    Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other instance.

  • CompareTo (object? obj) public int CompareTo(object? obj)

    Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other instance.

  • Equals (ValueTuple<T1> other) public bool Equals(ValueTuple<T1> other)

    Indicates whether the current instance is equal to another object of the same type.

  • Equals (object? obj) public bool Equals(object? obj)

    Indicates whether the current instance is equal to another object.

  • GetHashCode () public int GetHashCode()

    Returns the hash code for the current instance.

  • ToString () public override string ToString()

    Converts the value of the current ValueTuple<T1> struct to its equivalent string representation.

  • ITuple.Get object? ITuple.Get(int index)

    Gets the element at the specified index of the tuple.

  • ITuple.Length int ITuple.Length { get; }

    Gets the number of elements in the tuple.

  • ITuple.ToString string ITuple.ToString()

    Returns a string representation of the tuple.

Operators

  • == (ValueTuple<T1> t1, ValueTuple<T1> t2) public static bool operator ==(ValueTuple<T1> t1, ValueTuple<T1> t2)

    Compares two ValueTuple<T1> structures for equality.

  • != (ValueTuple<T1> t1, ValueTuple<T1> t2) public static bool operator !=(ValueTuple<T1> t1, ValueTuple<T1> t2)

    Compares two ValueTuple<T1> structures for inequality.