public static SingletonExample GetInstance()
 {
     if (_uniqueInstance == null)
     {
         Console.WriteLine("Creating unique instance SingletonExample");
         _uniqueInstance = new SingletonExample();
     }
     Console.WriteLine("Returning instance SingletonExample");
     return(_uniqueInstance);
 }
示例#2
0
        static void Main(string[] args)
        {
            SingletonExample.GetInstance();
            SingletonExample.GetInstance();
            SingletonExample.GetInstance();
            SingletonExample.GetInstance();

            ChocolateBoiler.GetInstance();
            ChocolateBoiler.GetInstance();
            ChocolateBoiler.GetInstance();
            ChocolateBoiler.GetInstance();

            SingletonExampleChargerFast.GetInstance();
            SingletonExampleChargerFast.GetInstance();
            SingletonExampleChargerFast.GetInstance();
            SingletonExampleChargerFast.GetInstance();

            Console.ReadKey();
        }