Skip to content

Prompt choices dynamically #167

Answered by patriksvensson
joserocha asked this question in Q&A
Discussion options

You must be logged in to vote

@joserocha Not sure I understand what you mean, but does something like this solve it for you?

// Build the fruit list
var fruits = new List<string>();
fruits.Add("banana");
fruits.Add("orange");

// Build the prompt
var prompt = new TextPrompt<string>("What's your [green]favorite fruit[/]?");
foreach(var fruit in fruits) {
   prompt.AddChoice(fruit);
}

// Show the prompt
var selectedFruit = AnsiConsole.Prompt(prompt);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@joserocha
Comment options

Answer selected by patriksvensson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #167 on December 14, 2020 08:20.