Skip to content

MultiSelect

The MultiSelect prompt lets the user choose multiple items from a list using checkboxes.

Basic Usage

csharp
var cities = Prompt.MultiSelect("Which cities would you like to visit?",
    new[] { "Seattle", "London", "Tokyo", "New York", "Singapore", "Shanghai" },
    pageSize: 3);
Console.WriteLine($"You picked {string.Join(", ", cities)}");

Parameters

ParameterTypeDescription
messagestringThe message to display to the user
itemsIEnumerable<T>?Items to select from (auto-generated for enum types)
pageSizeintNumber of items to display per page (default: unlimited)
minimumintMinimum number of items that must be selected (default: 1)
maximumintMaximum number of items that can be selected (default: unlimited)
defaultValuesIEnumerable<T>?Items selected by default
textSelectorFunc<T, string>?Function to convert items to display text

Options Class

csharp
var cities = Prompt.MultiSelect(new MultiSelectOptions<string>
{
    Message = "Which cities would you like to visit?",
    Items = new[] { "Seattle", "London", "Tokyo", "New York", "Singapore", "Shanghai" },
    PageSize = 3,
    Minimum = 1,
    Maximum = 3,
    DefaultValues = new[] { "Tokyo" }
});

Properties

PropertyTypeDefaultDescription
ItemsIEnumerable<T>Items to select from
DefaultValuesIEnumerable<T>[]Items selected by default
PageSizeintint.MaxValueNumber of items per page
Minimumint1Minimum number of selections required
Maximumintint.MaxValueMaximum number of selections allowed
TextSelectorFunc<T, string>x => x.ToString()!Display text selector
LoopingSelectionbooltrueWhether to loop at the beginning/end of the list

With Enum Type

csharp
var values = Prompt.MultiSelect<MyEnum>("Select enum values", defaultValues: new[] { MyEnum.Bar });
Console.WriteLine($"You picked {string.Join(", ", values)}");

Fluent API

csharp
using Sharprompt.Fluent;

var cities = Prompt.MultiSelect<string>(o => o.WithMessage("Which cities would you like to visit?")
                                               .WithItems(new[] { "Seattle", "London", "Tokyo" })
                                               .WithPageSize(3));

Released under the MIT License.