用C#实现一个类,要求该类只能被实例化一次

 1Singleton模式:
 2using System;
 3public class Singleton
 4{
 5private static Singleton instance;
 6private Singleton() {}
 7public static Singleton Instance
 8{
 9get
10{
11if (instance == null)
12{
13instance = new Singleton();
14}

15return instance;
16}

17}

18}

19

using System;
public class Singleton
{
private static readonly Singleton instance=new Singleton() ;
private Singleton() {}
public static Singleton Instance
{
    return instance;
}

}

posted @ 2007-03-25 01:58  白虎  阅读(981)  评论(0编辑  收藏  举报
非常感谢dudu,感谢博客园提供的各种服务。
联系白虎(David.Du)