一个static的class处理

yudi010 2009-11-29 10:41:29
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test1_constrator
{
class Program
{
static void Main(string[] args)
{
Class1 o1 = new Class1();

Class1 o2 = new Class1();
}
}
class Class1
{
private static int count = 0;
static Class1(){
count++;
System.Console.Write("Static" + count.ToString());
}
public Class1()
{
count++;
System.Console.Write("Public" + count.ToString());
}
}

}


想问一下, static Class1()到底起了什么作用呢?
...全文
50 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
绝代坏坏 2009-11-29
  • 打赏
  • 举报
回复
静态构造函数,类在被实例化的时候会被执行一次,注意,只会执行一次。
Sugar_Tiger 2009-11-29
  • 打赏
  • 举报
回复
静态构造方法.

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧