SystemExt/Terminal/Prompt.cs
/// <summary>
/// Prompts the user to enter a boolean answer to a question.
/// </summary>
/// <param name="question">
/// The question to ask the user.
/// </param>
/// <param name="defaultValue">
/// The answer to return if the user just presses enter.
/// </param>
/// <returns>
/// The response given by the user converted to a boolean.
/// </returns>
Prompts the user to enter a boolean answer to a question.
Prompts the user to enter a boolean answer to a question .
public static bool Boolean(string question, bool defaultValue = false)
        {
            while (true)
            {
                var input = Prompt.String(question, defaultValue ? "yes" : "no");
                switch (input)
                {
                    case "1":
                    case "on":
                    case "yes":
                    case "y":
                        return true;
                    case "0":
                    case "no":
                    case "n":
                    case "off":
                        return false;
                    default:
                        Console.Error.WriteLine("You must enter a boolean value (i.e. yes or no).");
                        break;
                }
            }
        }
public static bool Boolean ( string question , bool defaultValue = false ) { while ( true ) { var input = Prompt . String ( question , defaultValue ? " " : " " ) ; switch ( input ) { case " " : case " " : case " " : case " " : return true ; case " " : case " " : case " " : case " " : return false ; default : Console . Error . WriteLine ( " " ) ; break ; } } }
Prompts the user to enter a boolean answer to a question.
Prompts the user to enter a boolean answer to a question .
The response given by the user converted to a boolean.
The response given by the user converted to a boolean .
question
string
The question to ask the user.
The question to ask the user .
defaultValue
bool
The answer to return if the user just presses enter.
The answer to return if the user just presses enter .