/*使用静态方法实现单例模式*/ public static SingleTon getInstance() { if (instance == null) { instance = new SingleTon(); } return(instance); }
static void Main(string[] args) { SingleTon.getInstance().Print(); SingleTon.Instance.Print(); //泛型单例 Dog.getInstance().DogPrint(); Cat.getInstance().CatPrint(); Console.ReadKey(); //Console.WriteLine("Hello World!"); }