示例#1
0
        private int GetMainMenuValidInput()
        {
            bool isInputValid = false;
            int  userInput    = 0;

            while (!isInputValid)
            {
                try
                {
                    OutputManager.ShowMainMenuScreen();
                    userInput = InputManager.GetInputAndConvertToInt();
                    isInRange(userInput, 1, 7);
                    isInputValid = true;
                }
                catch (FormatException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
                catch (ValueOutOfRangeException ex)
                {
                    OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message));
                    pressToContinue();
                }
            }

            return(userInput);
        }