Ejemplo n.º 1
0
 public static PhoneBookManager CreateMangerInstance() //반환타입이 PhoneBookManager인 메서드 생성, static 을 붙여서 인스턴스 생성 없이 부름
 {
     if (inst == null)
     {
         inst = new PhoneBookManager(); //inst가 널이면 새로운 PhoneBookManager()생성
     }
     return(inst);                      //이미 생성되었다면 원래있던 inst 전달
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            PhoneBookManager manager = PhoneBookManager.CreateMangerInstance(); //싱글톤

            //manager.ReadToFile();
            while (true)
            {
                try
                {
                    int choice;
                    while (true)
                    {
                        manager.ShowMenu();
                        if (int.TryParse(Console.ReadLine(), out choice))
                        {
                            if (choice < 1 || choice > 6)
                            {
                                throw new MenuChoiceException(choice);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    switch (choice)
                    {
                    case 1: manager.InputData(); break;

                    case 2: manager.ListData(); break;

                    case 3: manager.SearchData(); break;

                    case 4: manager.SortData(); break;

                    case 5: manager.DeleteData(); break;

                    case 6: manager.WriteToFile();
                        Console.WriteLine("프로그램을 종료합니다"); return;
                    }
                }
                catch (MenuChoiceException err)
                {
                    err.ShowWrongChoice();
                }
                catch (Exception err)
                {
                    Console.WriteLine(err.Message);
                }
            }
        }