Esempio n. 1
0
        static void Main(string[] args)
        {
            // This will not work since the constructor is private
            // SingleObject singleObject = new SingleObject();

            SingleObject.GetInstance().ShowMessage();
            Console.ReadKey();
        }
Esempio n. 2
0
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        public static void Main(string[] args)
        {
            var singleObjectInstance = SingleObject.GetSingleObjectInstance();

            singleObjectInstance.ShowMessage();

            Console.ReadKey();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            //不合法的构造函数
            //编译时错误:构造函数 SingleObject() 是不可见的
            //SingleObject object = new SingleObject();

            //获取唯一可用的对象
            SingleObject obj = SingleObject.getInstance();

            //显示消息
            obj.showMessage();

            Console.ReadKey();
        }