コード例 #1
0
        public static void Main()
        {
            MainMenu.displayMenu();

            //create brain object
            ListManagerBrain brain = new ListManagerBrain();
            string           userAction;

            do
            {
                userAction = Console.ReadLine();

                switch (userAction)
                {
                case "1":
                    brain.AddItemToList();
                    //ListManagerBrain.AddItemToList();
                    //brain.ListItemChangeNotification();
                    //MainMenu.displayMenu();
                    break;

                case "2":
                    brain.RemoveItemFromList();
                    //ListManagerBrain.RemoveItemFromList();
                    //brain.ListItemChangeNotification();
                    //MainMenu.displayMenu();
                    break;

                case "3":
                    brain.ClearList();
                    //MainMenu.displayMenu();
                    break;

                case "4":
                    brain.ViewList();
                    break;

                case "5":
                    //close app and pass exit code of 0. If we were closing because of an error then pass -1
                    Environment.Exit(0);
                    break;

                default:
                    MainMenu.displayMenu();
                    break;
                }
            }while (userAction != "5");
        }
コード例 #2
0
        public static void Main()
        {
            //note: wrong order of statements - you ain't getting output till you enter something
            string userAction = Console.ReadLine();

            MainMenu.displayMenu();

            //note: Do-while probably is better suited than while for this
            // also - you are stuck on loop here as you don't re-assign userAction
            while (userAction != "5")
            {
                MainMenu.displayMenu();

                //note: this probably should be saved in variable and switch statement used instead of blocks of if/else
                // also no need to call MainMenu.displayMenu() here
                if (Console.ReadLine() == "1")
                {
                    ListManagerBrain.AddItemToList();
                    // note: calling ItemChangeNotification belongs to LIstManagerBrainLogic instead of MainApp
                    ListManagerBrain.ListItemChangeNotification();
                    MainMenu.displayMenu();
                }


                else if (Console.ReadLine() == "2")
                {
                    ListManagerBrain.RemoveItemFromList();
                    ListManagerBrain.ListItemChangeNotification();
                    MainMenu.displayMenu();
                }

                else if (Console.ReadLine() == "3")
                {
                    ListManagerBrain.ClearList();
                    MainMenu.displayMenu();
                }

                else if (Console.ReadLine() == "4")
                {
                    ListManagerBrain.ViewList();
                }
            }
        }