c# 静态构造函数(转)


   静态构造函数:  

静态构造函数用于初始化任何静态数据,或用于执行仅需执行一次的特定操作。在创建第一个实例或引用任何静态成员之前,将自动调用静态构

造函数。
 1public class Bus
 2{
 3    // Static constructor:
 4    static Bus()
 5    {
 6        System.Console.WriteLine("The static constructor invoked.");
 7    }

 8
 9    public static void Drive()
10    {
11        System.Console.WriteLine("The Drive method invoked.");
12    }

13}

14
15class TestBus
16{
17    static void Main()
18    {
19        Bus.Drive();
20    }

21}
posted @ 2007-07-05 20:21  刘雨赣  阅读(198)  评论(0编辑  收藏  举报