Ejemplo n.º 1
0
 private static void CheckEquality(SingletonLazyThreadSafe singleton1, SingletonLazyThreadSafe singleton2)
 {
     if (singleton1 == singleton2)
     {
         Console.WriteLine("==");
     }
     if (singleton1.Equals(singleton2))
     {
         Console.WriteLine("equals");
     }
     if (object.ReferenceEquals(singleton1, singleton2))
     {
         Console.WriteLine("ReferenceEquals");
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var singleton1 = SingletonThreadSafe.GetSingleton();
            var singleton2 = SingletonThreadSafe.GetSingleton();

            CheckEquality(singleton1, singleton2);

            var singleton3 = SingletonLazyThreadSafe.GetSingleton().Value;
            var singleton4 = SingletonLazyThreadSafe.GetSingleton().Value;

            CheckEquality(singleton3, singleton4);

            var singleton5 = new SingletonLazyThreadSafe();

            CheckEquality(singleton4, singleton5);                  // Should not print anything as it vioaltes singleton

            Console.ReadKey();
        }