Study notes: C # constructor and destructor

Bibliography: C # 6.0 study notes - from the first line of the first C # code to the project design (Author Zhoujia An) P56


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace MyApp
{
    public class Test
    {
        // 构造函数
        public Test()
        {
            System.Diagnostics.Debug.WriteLine("构造函数被调用。");
            WriteLine("构造函数被调用。");
        }

        // 析构函数
        ~Test()
        {
            System.Diagnostics.Debug.WriteLine("析构函数被调用。");
            WriteLine("析构函数被调用。");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Test t = new Test();
            ReadLine();
        }
    }
}

operation result:

Published 33 original articles · won praise 1 · views 691

Guess you like

Origin blog.csdn.net/qq_41708281/article/details/104231318