namespace 单例设计模式 { class SingleObject { //单例设计模式 private SingleObject() { }//构造函数私有.防止new,保持唯一. private static SingleObject _singleObject;//静态字段充当全局变量. public static SingleObject GetSingleObject()//有则获取,没有则创建. { if (_singleObject == null) { _singleObject = new SingleObject(); } return _singleObject; } } }