zoukankan      html  css  js  c++  java
  • 理解析构函数的执行过程

    Code
    class First
        {
            
    public First()
            {
                System.Console.WriteLine(
    "First class start!");
            }
            
    ~First()
            {
                System.Console.WriteLine(
    "First's destructor is called");
                System.Console.ReadLine();
            }
        }

        
    class Second : First
        {
            
    public Second()
            {
                System.Console.WriteLine(
    "Second class start!");
            }
            
    ~Second()
            {
                System.Console.WriteLine(
    "Second's destructor is called");
            }
        }

        
    class Third : Second
        {
            
    public Third()
            {
                System.Console.WriteLine(
    "Third class start!");
            }
            
    ~Third()
            {
                System.Console.WriteLine(
    "Third's destructor is called");
            }
        }

        
    class TestDestructors
        {
            
    static void Main()
            {
                Third t 
    = new Third();
            }
        }

    First class start!

    Second class start!

    Third class start!

    Third's destructor is called

    Second's destructor is called

    First's destructor is called

    析构函数的执行过程实际是执行了Finalize方法,具体的方法实际是:

    protected overrid Finalize()

    {

      try

        {

          //implemention

        }

      Finally

        {

           base.Finalize();

        }

    }

  • 相关阅读:
    C++实现二叉树的相应操作
    C++对文件的操作
    C++与C的区别二
    C++多线程编程二
    C++多线程编程一
    C语言多线程编程二
    C语言多线程编程一
    HTML练习(三)
    磁盘/内存模式查询数据
    RestTemplate使用不当引发的问题分析
  • 原文地址:https://www.cnblogs.com/shineqiujuan/p/1500516.html
Copyright © 2011-2022 走看看