Exemple #1
0
 /*使用静态方法实现单例模式*/
 public static SingleTon getInstance()
 {
     if (instance == null)
     {
         instance = new SingleTon();
     }
     return(instance);
 }
Exemple #2
0
        static void Main(string[] args)
        {
            SingleTon.getInstance().Print();

            SingleTon.Instance.Print();

            //泛型单例
            Dog.getInstance().DogPrint();
            Cat.getInstance().CatPrint();


            Console.ReadKey();
            //Console.WriteLine("Hello World!");
        }