Deconstruction
Unpack tuples into separate variables.
What Is Deconstruction?
Deconstruction splits a tuple (or object) into separate variables in one statement, so you can name each part directly.
using System;
class Program
{
static void Main()
{
var point = (3, 4);
(int x, int y) = point;
Console.WriteLine("x=" + x + ", y=" + y);
}
}Deconstructing a Tuple
Put the target variables in parentheses on the left of =. Each receives the matching tuple element.
using System;
class Program
{
static void Main()
{
var user = ("Ada", 36);
(string name, int age) = user;
Console.WriteLine(name + " is " + age);
}
}