Deconstruction

C# deconstruction is a process of deconstruct instance of a class. It is helpful when we want to reinitialize object of a class.

Make sure all the parameters of deconstructor are out type.

Let's see an example.

C# Deconstruction Example

Example

using System;
namespace CSharpFeatures
{

    public class Student{
           private string Name;
           private string Email;
        public Student(string name, string email)
        {
            this.Name = name;
            this.Email = email;
        }
// creating deconstruct
        public void Deconstruct(out string name, out string email)
        {
            name  = this.Name;
            email = this.Email;
        }
    }

class DeconstructExample
    {
        static void Main(string[] args)
        {
            var student = new Student("irfan", "irfan@abc.com");
            var (name, email) = student;
            Console.WriteLine(name +" "+email);
        }
    }
}

Input Required

This code uses input(). Please provide values below: