C# this调用构造函数及析构函数
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace trainProject { public class Student { public string Name { get; set; } public int Age { get; set; } public char Sex { get; set; } public string Id { get; set; } public Student(string id, string name, int age, char sex) { this.Id = id; this.Name = name; this.Age = age; this.Sex = sex; }
//this :调用本类的其他构造函数 public Student(string id, string name) : this(id, name, 0, '1') { } public Student(string id, string name, int age) : this(id, name, age, '1') { } //析构函数 释放资源 ~Student() { Console.WriteLine("析构函数"); } } }