What are destructors in C# 7.0?

WBOY
Release: 2023-09-14 22:05:03
forward
1133 people have browsed it

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();
   }
}
Copy after login

Output

emp
fname
lname
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!