public void MethodNotThreadSafe()
        {
            SingletonNotThreadSafe instance = SingletonNotThreadSafe.Instance;

            Debug.WriteLine(instance);
            SingletonNotThreadSafe anotherInstance = SingletonNotThreadSafe.Instance;

            Debug.WriteLine(anotherInstance);

            Assert.AreEqual(instance, anotherInstance);
        }
コード例 #2
0
    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");
        }
    }
コード例 #3
0
 public static SingletonNotThreadSafe GetInstance() {
     if (instance == null) {
         instance = new SingletonNotThreadSafe();
     }
     return instance;
 }