Exemplo n.º 1
0
        public static Singleton Instance()
        {
            if (_instance == null)
            {
                _instance = new Singleton();
            }

            return _instance;
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            #region 结构实现
            // 创建一个实例s1
            Structural.Singleton s1 = Structural.Singleton.Instance();
            // 创建一个实例s2
            Structural.Singleton s2 = Structural.Singleton.Instance();

            if (s1 == s2)
            {
                Console.WriteLine("对象为相同实例");
            }
            #endregion

            Console.WriteLine("******************************");

            #region 实践应用

            #endregion

            Console.ReadKey();
        }