namespace 單例設計模式 { class SingleObject { //單例設計模式 private SingleObject() { }//構造函數私有.防止new,保持唯一. private static SingleObject _singleObject;//靜態字段充當全局變量. public static SingleObject GetSingleObject()//有則獲取,沒有則創建. { if (_singleObject == null) { _singleObject = new SingleObject(); } return _singleObject; } } }