Exemple #1
0
        static void Main(string[] args)
        {
            var singleton = Singleton.GetInstance();

            singleton.TextWrite();
            var lazySingleton = LazySingleton.GetInstance();

            lazySingleton.TextWrite();
            var lazyTemplateSingleton = LazyTemplateSingleton.GetInstance();

            lazyTemplateSingleton.TextWrite();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("饿汉式 单例类 的处理!");

            for (int i = 0; i < 10; i++)
            {
                EagerSingleton data = EagerSingleton.GetInstance();
                Console.WriteLine(data.DemoCount++);
            }


            Console.WriteLine("懒汉式 单例类 的处理!");

            for (int i = 0; i < 10; i++)
            {
                LazySingleton data = LazySingleton.GetInstance();
                Console.WriteLine(data.DemoCount++);
            }

            Console.ReadLine();
        }
 public void RunExample()
 {
     var singleton           = Singleton.GetInstance();
     var threadSafeSingleton = ThreadSafeSingleton.GetInstance();
     var lazySingleton       = LazySingleton.GetInstance();
 }
 void static Main(string[] args)
 {
     LazySingleton.GetInstance();
 }