记录学习过程
单例模式:单例模式就是保证一个类,只有一个实例;
class Singleton { private static Singleton _instance = null; private static readonly object SynObject = new object(); // 定义私有构造函数,使外界不能创建该类实例 private Singleton() { } public static Singleton Instance { get { if (_instance == null) { lock (SynObject) { if (_instance == null) { _instance = new Singleton(); } } } return _instance; } } }
原文:http://www.cnblogs.com/yizhituoxie/p/7833946.html