CSharp 10 Features

Last Updated: 4/11/2022

Mix Assignment and Declaration in Deconstruction

Previously, a deconstruction could assign all values to existing variables or newly declared variables.

public struct Point 
{
	public int X {get; set;}
	public int Y {get; set;}
	
	public void Deconstruct(out int x, out int y) 
	{
		x = X;
		y = Y;
	}
}

var point = new Point { X = 5, Y = 10 };
//existing variables
int x1 = 0;
int y1 = 0;
(x1, y1) = point;

//new declared variables
(int x2, int y2) = point;

Beginning in C# 10, you can mix variable declaration and assignment in a deconstruction.

//mix declaration and assignment
int x3;
(x3, int y3) = point;