Home  >  Article  >  Backend Development  >  What are destructors in C# 7.0?

What are destructors in C# 7.0?

WBOY
WBOYforward
2023-09-14 22:05:031084browse

C# 7.0 中的解构函数是什么?

C# allows the use of the same multiple destructor methods in the same program Number of output parameters or the same number and type of output parameters Different order.

It is part of the new tuple syntax - not related to the Tuple class, but taken from functional programming.

Deconstruct keyword is used for destructuring functions

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

The above is the detailed content of What are destructors in C# 7.0?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:What are events in C#?Next article:What are events in C#?