Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Singleton s1 = Singleton.Instance();
            Singleton s2 = Singleton.Instance();

            if (s1 == s2)
            {
                Console.WriteLine("s1 and s2 are the same instance.");
            }

            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void RunSingleton()
        {
            // 单体对象只有一个
            // 单体构造函数不能是public 防止重复
            Singleton s1 = Singleton.Instance();
            Singleton s2 = Singleton.Instance();

            // Test for same instance
            if (s1 == s2)
            {
                Console.WriteLine("Objects are the same instance");
            }
        }