コード例 #1
0
        static void Main(string[] args)
        {
            clock c1 = clock.getInstance();
            clock c2 = clock.getInstance();
            clock c3 = clock.getInstance();

            Console.Write("By c1, the time is: ");
            c1.printTime();

            Console.Write("By c2, the time is: ");
            c2.printTime();

            Console.Write("By c3, the time is: ");
            c3.printTime();
        }
コード例 #2
0
        public static clock getInstance()
        {
            if (INSTANCE != null)
            {
                return(INSTANCE);
            }
            lock (key)
            {
                if (INSTANCE == null)
                {
                    INSTANCE = new clock();
                }

                return(INSTANCE);
            }
        }