P0_TrevorGraham/StoreApplication/StoreMain/UI/StoreCLI.cs
/// <summary>
/// Given a list of options in the form of a string array, this method will print out the options and return a valid number option or die trying.
/// </summary>
/// <returns></returns>
Given a list of options in the form of a string array, this method will print out the options and return a valid number option or die trying.
Given a list of options in the form of a string array this method will print out the options and return a valid number option or die trying .
public int ChooseOptionFromList(string intro = "Please choose an option: ",string[] options = null){
            if(options == null || options.Length == 0){
                throw new Exception("StoreCLI.cs: ChooseOptionFromList: something isn't giving options to this method!!! Give it a valid list of options!!!");
            }
            int userChoice = -1;
            bool validChoice = false;
            while(!validChoice){
                Console.WriteLine(intro);
                for(int i =0;i<options.Length;i++){
                    Console.WriteLine(i+". "+options[i]+"\n");
                }
                Console.WriteLine("Select an option by typing in the number next to the desired option.");
                validChoice = IsValidNumberOption(Console.ReadLine(),options.Length, out userChoice);
                if(!validChoice){
                    Console.WriteLine("\nYou have tried to enter an invalid option.\nPlease choose a valid option.\n");
                }
            }
            return userChoice;
        }
public int ChooseOptionFromList ( string intro = " " , string [ ] options = null ) { if ( options == null || options . Length == 0 ) { throw new Exception ( " " ) ; } int userChoice = - 1 ; bool validChoice = false ; while ( ! validChoice ) { Console . WriteLine ( intro ) ; for ( int i = 0 ; i < options . Length ; i ++ ) { Console . WriteLine ( i + " " + options [ i ] + " \n " ) ; } Console . WriteLine ( " " ) ; validChoice = IsValidNumberOption ( Console . ReadLine ( ) , options . Length , out userChoice ) ; if ( ! validChoice ) { Console . WriteLine ( " \n \n \n " ) ; } } return userChoice ; }
Given a list of options in the form of a string array, this method will print out the options and return a valid number option or die trying.
Given a list of options in the form of a string array this method will print out the options and return a valid number option or die trying .
//keep pestering the user until they pick a valid choice
None
intro
string
options
string[]