C# Feature – Tuples
Overview
Section titled “Overview”Tuples group multiple values with names, returning multiple results without custom types.
Introduced In
Section titled “Introduced In”C# 7 (2017)
Before
Section titled “Before”class Pair { public int X; public int Y; }
(int X, int Y) p = (1, 2);
Annotated Example
Section titled “Annotated Example”var (sum, count) = Aggregate(xs);
Gotchas & Best Practices
Section titled “Gotchas & Best Practices”- Prefer meaningful names for tuple elements.
Related Features
Section titled “Related Features”Version Notes
Section titled “Version Notes”- Works with deconstruction assignment.