예제 #1
0
        static void Main(string[] args)
        {
            //first call
            var config1 = Singleton.getInstance();

            config1.SessionName = "AMOS";
            Console.WriteLine("first call," + config1.SessionName);
            //second call
            var config2 = Singleton.getInstance();

            Console.WriteLine("second call," + config2.SessionName);
            Console.ReadKey();
        }
예제 #2
0
        void Start()
        {
            Debug.Log("Start");
            Singleton obj1 = Singleton.getInstance();
            Singleton obj2 = Singleton.getInstance();

            if (obj1 == obj2)
            {
                Debug.Log("*obj1とobj2は同じインスタンスです。*");
            }
            else
            {
                Debug.Log("*obj1とobj2は同じインスタンスではありません。*");
            }
            Debug.Log("*End.*");
        }
예제 #3
0
        static void Main(string[] args)
        {
            WriteLine("start");
            Singleton obj1 = Singleton.getInstance();
            //Singleton obj2 = new Singleton(); 构造函数设置成私有的,不能通过new 创建该类的实例
            Singleton obj2 = Singleton.getInstance();

            if (obj1.Equals(obj2))
            {
                WriteLine("obj1与obj2是相同的实例。");
            }
            else
            {
                WriteLine("obj1与obj2不是相同的实例。");
            }
            WriteLine("end");
            ReadKey();
        }