class Program { static void Main(string[] args) { //Single s1 = new Single(); Single s1 = Single.Default(); Console.WriteLine(s1.Num); s1.Num = 100; Single s2 = Single.Default(); Console.WriteLine(s2.Num); Console.ReadKey(); } } class Single { //阻止它被new //禁止在外界调用构造方法public Single() private Single()//单例一般采用声明一个静态构造函数 { num = 10; } public static Single single; public static Single Default() { if (single==null) { return single = new Single(); } else { return single; } } private int num; public int Num { get { return num; } set { num = value; } } }