← Back to Home • Next: Confirm — Methods →
A yes/no question. The user presses the culture-specific Yes or No key and the control returns immediately.
Confirm is a preset of the KeyPress control. It returns the very same
IKeyPressControl interface and behaves identically — the only difference is that the Yes and No
keys for the current culture are already registered as valid keys for you, so the user can only
answer with Yes or No.
🔑 Because Confirm is a KeyPress, its full API reference lives on the KeyPress pages. This page focuses on the yes/no pattern and how to read the result. See Methods, Operations, and Styles here for the short version with links to the shared reference.
| Sub-page | What you will find |
|---|---|
| Index (this page) | The yes/no pattern and how to interpret the return value |
| Methods | The shared IKeyPressControl API (links to the KeyPress reference) |
| Operations | Runtime behavior (links to the KeyPress reference) |
| Styles | The KeyPressStyles regions (links to the KeyPress reference) |
Use Confirm when… |
Consider instead… |
|---|---|
| You need a plain yes/no answer | — |
| You need a different single-key choice (A / B / C) | KeyPress |
| You need to pick from a labelled list | Select |
using PromptPlusLibrary;
var confirm = PromptPlus.Controls
.Confirm("Apply changes?")
.Run();
if (confirm.IsAborted)
{
PromptPlus.Console.WriteLine("Cancelled.");
}
else if (confirm.Content is { } k &&
char.ToUpperInvariant(k.KeyChar) == char.ToUpperInvariant(PromptPlus.Config.YesChar))
{
PromptPlus.Console.WriteLine("Yes — applying changes.");
}
else
{
PromptPlus.Console.WriteLine("No — nothing changed.");
}
Confirm("Apply changes?") creates the control with the culture Yes/No keys pre-registered..Run() returns a ResultPrompt<ConsoleKeyInfo?> — exactly
like KeyPress, not a bool.KeyChar to
PromptPlus.Config.YesChar. Anything else that reached .Content
(the No key) is a “no”.💡 The Yes/No keys follow the current culture. In
en-USthey are Y/N; settingPromptPlus.Config.DefaultCultureto another culture (e.g.pt-BR) switches them to that culture’s letters, andPromptPlus.Config.YesChar/NoCharreflect the active pair.
Confirm returns ResultPrompt<ConsoleKeyInfo?> — identical to KeyPress.
| Member | Meaning |
|---|---|
.Content |
The pressed key as a nullable ConsoleKeyInfo? (no value when aborted) |
.IsAborted |
true when the user pressed Esc / the abort key |
Interpret it with the Yes-char comparison shown above:
static bool IsYes(ResultPrompt<ConsoleKeyInfo?> r) =>
!r.IsAborted &&
r.Content is { } k &&
char.ToUpperInvariant(k.KeyChar) == char.ToUpperInvariant(PromptPlus.Config.YesChar);
Always branch on
.IsAbortedfirst — an aborted confirm has no.Contentvalue and is neither “yes” nor “no”.
Like KeyPress, Confirm takes an optional prompt, description, and showresult flag:
PromptPlus.Controls
.Confirm("Apply changes", "Press the culture-specific Yes/No key")
.Run();
IKeyPressControl Confirm(string prompt = "", string? description = null, bool showresult = false)
KeyPressStyles regionsYesChar, NoChar, DefaultCulture