static方法笔记

class Program
{

static void Main(string[] args)
{
A o1 = new A();
A o2 = new A();
Console.WriteLine(A.Count);
}
}

class A
{
public static int Count = 0;
static A()
{
Count++;
}
public A()
{
Count++;
}
}

 

最后的输入结果是3,static方法在程序开始时运行一次

http://www.cnblogs.com/GT_Andy/archive/2010/04/09/1921797.html

你可能感兴趣的:(static)