public static Singleton2 GetInstance() { if (Instance == null)//糟糕代码,多线程不安全 { Instance = new Singleton2(); } return(Instance); }
public static Singleton2 GetInstance2() { lock (padlock)//线程安全,但是效率太低 { if (Instance == null) { Instance = new Singleton2(); } } return(Instance); }