Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Desconstruction in C# 7
// Descontruct a custom type
(var age, var name) = new Student(); // calls Deconstruct(out myX, out myY);
Console.WriteLine("Student info:");
Console.WriteLine($ "Age: {age}");
Console.WriteLine($ "Name: {name}");
public class Student {
public int Age { get; set;}
public string Name { get; set; }
// This needs to be named Deconstruct
public void Deconstruct(out int age, out string name) {
age = Age;
name = Name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment