Esempio n. 1
0
File: Program.cs Progetto: slsk36/C-
 public static SingleTest getInstance()
 {
     if (inst == null)
     {
         inst = new SingleTest(rd);
     }
     return(inst);
 }
Esempio n. 2
0
File: Program.cs Progetto: slsk36/C-
        static void Main(string[] args)
        {
            Random r = new Random();

            //일반적인 객체 생성
            SingleTest test1 = new SingleTest(r);

            Console.WriteLine(test1.getData());
            Console.WriteLine(new SingleTest(r).getData());
            Console.WriteLine(new SingleTest(r).getData());

            //싱글톤
            Console.WriteLine(SingleTest.getInstance().getData());
            Console.WriteLine(SingleTest.getInstance().getData());
            Console.WriteLine(SingleTest.getInstance().getData());
        }