Skip to main content
Named tuple elements are compile-time constructs in C# that assign semantic identifiers to the fields of a System.ValueTuple structure. They replace the default Item1, Item2, …, ItemN field names with user-defined aliases, providing stronger typing semantics at the source-code level without altering the underlying runtime type.

Syntax and Initialization

Named elements can be defined either on the left-hand side (type declaration) or the right-hand side (value initialization) of an assignment.
Starting with C# 7.1, the compiler supports tuple projection initializers, which automatically infer the element names from the variables or properties used to initialize the tuple.

Compiler Mechanics and Metadata

Named tuples are syntactic sugar. At the Common Language Runtime (CLR) level, named tuples do not exist; they are compiled down to standard System.ValueTuple<T1, T2, ...> structs. The compiler handles the translation of your custom names to the underlying ItemN fields. Because of this, the default ItemN fields remain accessible even when custom names are provided.
When a named tuple is returned from a method or exposed as a property, the compiler preserves the element names across assembly boundaries by applying the [TupleElementNames] attribute to the member in the emitted Intermediate Language (IL) metadata.

Assignment and Type Compatibility

Tuple element names are not part of the tuple’s strict type identity. Type compatibility during assignment is determined exclusively by the arity (number of elements) and the sequence of types. Element names are entirely ignored during assignment.

Equality and Comparison

Because element names are erased at runtime, the equality operators (== and !=) evaluate tuples based on positional values, bypassing the names completely.

Deconstruction

When deconstructing a named tuple into separate variables, the extraction is strictly positional. The names of the tuple elements do not need to match the names of the target variables.
Tired of Poor C# Skills? Fix That With Deep Grasping!Learn More