Created
November 1, 2017 04:01
-
-
Save Ibro/6c9688cb5680b9128e3e1dbc8b29b8ae to your computer and use it in GitHub Desktop.
Desconstruction in C# 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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