Glossary / Tuples

Tuples

C# tuples group multiple values into one lightweight value without requiring a named domain type. Value tuples ((T1, T2)) support named elements, deconstruction, and convenient method returns; they are best for local or short-lived groupings where a dedicated type would add little meaning.

ValueTuple behavior

(string Name, int Age) person = ("Ada", 36);
var (name, age) = person;

Tuple element names improve source readability but are not part of runtime identity in the same way as a nominal type; assignment compatibility generally depends on element types/order, and names can be ignored or inferred. Value tuples are structs, so assignment copies them; contained references remain shared. Equality compares corresponding elements when supported. Tuple literals are target-typed in many contexts.

Do not confuse System.ValueTuple with legacy System.Tuple<T...>, which is a reference type with properties such as Item1 and has different allocation and API characteristics. Large tuple returns can become hard to understand and fragile when element order changes.

When to use a named type

Use a tuple for a local calculation, small private method return, or temporary projection. Use a class/record/struct when the data has domain meaning, validation, behavior, documentation, versioning requirements, or should be independently discoverable in an API. Public tuple signatures can be awkward to evolve.

Interview questions

  1. Are value tuples reference types? No; ValueTuple types are structs.
  2. Are element names runtime type identity? They primarily improve source/metadata presentation; tuple compatibility is based on element types and positions.
  3. When prefer a record? When data has stable domain meaning, invariants, behavior, or an evolvable public contract.
  4. How does deconstruction work? It assigns tuple elements to variables in positional order.
  5. Tuple vs System.Tuple? ValueTuple is value-based and supports language tuple syntax; legacy Tuple is a reference type.

References