Skip to content

Instantly share code, notes, and snippets.

@Ibro
Created November 1, 2017 04:01
Show Gist options
  • Save Ibro/6c9688cb5680b9128e3e1dbc8b29b8ae to your computer and use it in GitHub Desktop.
Save Ibro/6c9688cb5680b9128e3e1dbc8b29b8ae to your computer and use it in GitHub Desktop.
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