public static ChocolateBoiler GetInstance()
 {
     if (_chocolateBoiler == null)
     {
         Console.WriteLine("Creating ChocolateBoiler");
         _chocolateBoiler = new ChocolateBoiler();
     }
     Console.WriteLine("Returning ChocolateBoiler");
     return(_chocolateBoiler);
 }
예제 #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();
        }