C#设计模式01 单例模式
C#设计模式01 单例模式
单例模式一
public class Singleton private static object mylock = new object(); private Singleton() //首次初始化信息 public static Singleton CreateInstance() if(singleton == null) lock(mylock) if(singleton==null) singleton = new Singleton(); } return singleton; } 单例模式二 { private SingletonSecond() //首次初始化信息 static SingletonSecond() singleton = new SingletonSecond(); public static SingletonSecond CreateInstance() return singleton; }
单例模式三 { private SingletonThird() //首次初始化信息 static SingletonThird() singleton = new SingletonThird(); }
{ private SingletonThird1() //首次初始化信息 }
{ { }
}