static

 

代码
1 class Counter
2 {
3 private static int count = 0;
4
5 public Counter()
6 {
7 count++;
8 }
9
10 public static int Count
11 {
12 get
13 {
14 return count;
15 }
16 }
17 }
18
19
20
21 class Program
22 {
23 static void Main(string[] args)
24 {
25
26 Counter c1 = new Counter();
27 Counter c2 = new Counter();
28 Counter c3 = new Counter();
29 Console.WriteLine("count类有{0}个实例",Counter.Count);
30 Console.ReadKey();
31 }
32 }

 

输出结果:

posted @ 2010-06-03 15:23  冰棒冰  阅读(265)  评论(1)    收藏  举报