示例#1
0
 public static SingletonTypical getInstance()
 {
     if (instance == null)
     {
         instance = new SingletonTypical();
     }
     return(instance);
 }
示例#2
0
        public static void Run()
        {
            Console.WriteLine("\r\n\tSingleton\r\n");

            var obj1 = SingletonTypical.getInstance();

            Console.WriteLine($"obj1 id = {obj1.Name}");

            var obj2 = SingletonTypical.getInstance();

            Console.WriteLine($"obj2 id = {obj2.Name}");

            var obj3 = SingletonLazy.GetInstance();

            Console.WriteLine($"obj3 id = {obj3.Name}");

            var obj4 = SingletonLazy.GetInstance();

            Console.WriteLine($"obj4 id = {obj4.Name}");
        }