public static SingleTest getInstance() { if (inst == null) { inst = new SingleTest(rd); } return(inst); }
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()); }