Skip to content

Simple .NET Console menu. Implements IEnumerable and ICollection

License

Notifications You must be signed in to change notification settings

RobinClaesson/CommandLineMenu

Repository files navigation

CommandLineMenu

NuGet Version

.NET Library for creating menus that prompts the user to select an option and gives back the selected alternative.

Menu<T>

Menu<T> is the main class for creating and displaying menus. It implements IList<T> with the menu alternatives as the collection elements.

Create Menu

There are several ways to instantiate a new menu, see more examples in CommandLineMenu.Examples:

// Create Menu and add alternatives one by one
var menu = new Menu<string>();
menu.Add("Alternative 1");
menu.Add("Alternative 2");
menu.Add("Alternative 3");

// Create Menu with IEnumerable initialisation
var menu = new Menu<string> { "Alternative 1", "Alternative 2", "Alternative 3" };

// Create Menu from existing IEnumerable using IEnumerable.ToMenu()
var alternatives = new List<string> { "Alternative 1", "Alternative 2", "Alternative 3" };
var menu = alternatives.ToMenu();

// Create Menu from other object type
enum Alternatives { Alternative1, Alternative2, Alternative3 }
var menu = Enum.GetValues<Alternatives>().ToMenu();

Display Menu

To display a menu and get the object for the chosen alternative we call ShowMenu():

var result = menu4.ShowMenu();

Console application displaying menu

About

Simple .NET Console menu. Implements IEnumerable and ICollection

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages