[C#] C#构造函数、静态构造函数、析构函数的用法 →→→→→进入此内容的聊天室

来自 , 2020-12-05, 写在 C#, 查看 111 次.
URL http://www.code666.cn/view/9dee60d3
  1. using System;
  2. class Test2
  3.    {
  4.       static int i;
  5.       static Test2() { // a constructor for the entire class called
  6.                        //once before the first object created
  7.               i = 4;
  8.          Console.Out.WriteLine("inside static construtor...");
  9.       }
  10.       public Test2() {
  11.          Console.Out.WriteLine("inside regular construtor... i={0}",i);
  12.       }
  13.       ~Test2() { // destructor (hopefully) called for each object
  14.        Console.Out.WriteLine("inside destructor");
  15.       }
  16.      
  17.       static void Main(string[] args)
  18.       {
  19.          Console.Out.WriteLine("Test2");
  20.          new Test2();
  21.          new Test2();
  22.       }
  23.    }
  24.  
  25.  
  26.  
  27. //csharp/4819

回复 "C#构造函数、静态构造函数、析构函数的用法"

这儿你可以回复上面这条便签

captcha