C# Feature – Deconstruction
Overview
Section titled “Overview”Deconstruction syntax assigns multiple values in one statement from tuples or types with Deconstruct methods.
Introduced In
Section titled “Introduced In”C# 7 (2017)
Before
Section titled “Before”var t = GetPoint();var x = t.X; var y = t.Y;
var (x, y) = GetPoint();
Annotated Example
Section titled “Annotated Example”public readonly struct Point(int x, int y){ public int X { get; } = x; public int Y { get; } = y;}
Gotchas & Best Practices
Section titled “Gotchas & Best Practices”- Ensure Deconstruct methods are in scope.
Related Features
Section titled “Related Features”Version Notes
Section titled “Version Notes”- Extended patterns support richer deconstruction cases.