Exemple #1
0
 public static SingleTonClass GetInstance()
 {
     //remove if condition, if 5 object needs to create
     if (Instance == null)
     {
         Instance = new SingleTonClass();
     }
     return(Instance);
 }
Exemple #2
0
        static void Main_05(string[] args)
        {
            Console.WriteLine("Hello World!");

            SingleTonClass sgObj1 = SingleTonClass.GetInstance();

            Console.WriteLine($"counter for obj1 : {SingleTonClass.counter}");
            sgObj1.Display();
            SingleTonClass sgObj2 = SingleTonClass.GetInstance();

            Console.WriteLine($"counter for obj2: {SingleTonClass.counter}");
            sgObj2.Display();
            SingleTonClass sgObj3 = SingleTonClass.GetInstance();

            SingleTonClass sgObj4 = SingleTonClass.GetInstance();
            SingleTonClass sgObj5 = SingleTonClass.GetInstance();
        }