Exemplo n.º 1
0
Arquivo: Program.cs Projeto: slsk36/C-
 public static SingleTest getInstance()
 {
     if (inst == null)
     {
         inst = new SingleTest(rd);
     }
     return(inst);
 }
Exemplo n.º 2
0
Arquivo: Program.cs Projeto: 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());
        }