• 理解析构函数的执行过程


    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();

        }

    }

  • 相关阅读:
    技巧:在Silverlight应用程序中操作Cookie
    python 调用云语音服务,文本模板转语音通知
    java 9. 面向对象之方法设计
    java 7. 多维数组
    深拷贝浅拷贝
    mock demo
    Java 5. 语法结构
    Java 1. 数据类型
    Java 2. 量与常量
    django 3. 路由初探
  • 原文地址:https://www.cnblogs.com/shineqiujuan/p/1500516.html
Copyright © 2020-2023  润新知