Prompt Class

Provides methods for creating interactive yes/no prompts in console applications.

public static class Prompt

Methods

NameDescription
YesNo(string, bool?)Prompts the user with a yes/no question using standard Y/N labels.
YesNo(string, string, string, bool?)Prompts the user with a yes/no question using custom labels. The prompt loops until the user provides a valid response.

YesNo overloads

YesNo(string, bool?)

Prompt.cs

Prompts the user with a yes/no question using standard Y/N labels.

public static bool YesNo(string question, bool? defaultValue)
Parameters
question string
The question to display to the user.
defaultValue bool?
The default value to use if the user presses Enter without typing a response, or if the standard input is closed. If null, the user must provide an explicit answer.
Returns

bool true if the user answered yes; otherwise, false.

Exceptions
EndOfStreamException
The standard input is closed and defaultValue is null.

YesNo(string, string, string, bool?)

Prompt.cs

Prompts the user with a yes/no question using custom labels. The prompt loops until the user provides a valid response.

public static bool YesNo(string question, string yesValue, string noValue, bool? defaultValue)
Parameters
question string
The question to display to the user.
yesValue string
The text representing a yes response (case-insensitive).
noValue string
The text representing a no response (case-insensitive).
defaultValue bool?
The default value to use if the user presses Enter without typing a response, or if the standard input is closed. If null, the user must provide an explicit answer.
Returns

bool true if the user answered yes; otherwise, false.

Exceptions
EndOfStreamException
The standard input is closed and defaultValue is null.