public static MySingleton getInstance()
 {
     if (instance == null)
     {
         instance = new MySingleton();
     }
     return(instance);
 }
        static void Main(string[] args)
        {
            var s1 = MySingleton.getInstance();
            var s2 = MySingleton.getInstance();

            if (s1 == s2)
            {
                Console.WriteLine("Objects are the same instance");
            }
            Console.ReadLine();
        }
Beispiel #3
0
 public static MySingleton GetInstance()
 {
     if (s == null)
     {
         lock (syncLock) {
             if (s == null)
             {
                 s = new MySingleton();
             }
         }
     }
     return(s);
 }
        static void Main(string[] args)
        {
            MySingleton mySingle = MySingleton.Instance;

            Console.ReadKey();
        }