
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What are Deconstructors in C# 7.0?
C# allows to use multiple deconstructor methods in the same program with the same number of out parameters or the same number and type of out parameters in a different order.
It's a part of the new tuple syntax - which has nothing to do with the Tuple<> classes but is taking from functional programming.
Deconstruct keyword is used for Deconstructors
Example
public class Employee{ public Employee(string employeename, string firstName, string lastName){ Employeename = employeename; FirstName = firstName; LastName = lastName; } public string Employeename { get; } public string FirstName { get; } public string LastName { get; } public void Deconstruct(out string employeename, out string firstName, out string lastName){ employeename = Employeename; firstName = FirstName; lastName = LastName; } } class Program{ public static void Main(){ Employee employee = new Employee("emp", "fname", "lname"); (string EName, string Fname, string Lname) = employee; System.Console.WriteLine(EName); System.Console.WriteLine(Fname); System.Console.WriteLine(Lname); Console.ReadLine(); } }
Output
emp fname lname
- Related Articles
- What are Local functions in C# 7.0?
- What are the improvements in Out Parameter in C# 7.0?
- What are binary literals and digit separators in C# 7.0?
- What are Ref locals and Ref returns in C# 7.0?
- What is Pattern Matching in C# 7.0?
- What are constants in C++?
- What are literals in C++?
- What are delegates in C#?
- What are events in C#?
- What are namespaces in C#?
- What are pointers in C#?
- What are indexers in C#?
- What are identifiers in C#?
- What are objects in C#?
- What are finalizers in C#?

Advertisements