public void MethodNotThreadSafe() { SingletonNotThreadSafe instance = SingletonNotThreadSafe.Instance; Debug.WriteLine(instance); SingletonNotThreadSafe anotherInstance = SingletonNotThreadSafe.Instance; Debug.WriteLine(anotherInstance); Assert.AreEqual(instance, anotherInstance); }
public static void SubMain(String[] args) { SingletonNotThreadSafe instance = SingletonNotThreadSafe.GetInstance(); Console.WriteLine(instance); SingletonNotThreadSafe anotherInstance = SingletonNotThreadSafe.GetInstance(); Console.WriteLine(anotherInstance); if (instance == anotherInstance) { Console.WriteLine("They are the same instance"); } }
public static SingletonNotThreadSafe GetInstance() { if (instance == null) { instance = new SingletonNotThreadSafe(); } return instance; }