using System.Collections.Generic;
public static void Main()
Menu mainMenu= new Menu("Main Menu");
mainMenu.add("1", "First Choice")
.add("2", "Mine Sweeper")
.add("Q", "Quit to DOS");;
KeyValuePair<string,string> choice = mainMenu.Invoke();
Console.WriteLine ("You choice: " + choice.Key + ". " + choice.Value);
switch (choice.Key.ToString())
Console.WriteLine("ok 1");
Console.WriteLine("ok 2");
Console.WriteLine("Huh?");
private SortedList<string, string> _options;
private bool _allowEscapeOrBlank;
public Menu(string Title)
this._options = new SortedList<string, string>();
this._allowEscapeOrBlank = false;
public Menu add(String key, String option)
this._options.Add(key, option);
public KeyValuePair<string, string> Invoke() {
int width = this.MaxOptionLength();
string headbar = new String('─', (width - this._title.Length - 2)/ 2);
Console.WriteLine("┌" + headbar + "[ " + this._title + " ]" + headbar + "┐");
Console.WriteLine("│" + new String(' ', width + 1) + "│");
foreach (KeyValuePair<string, string> kvp in this._options){
Console.WriteLine("│ " + kvp.Key + ". " + kvp.Value + new String(' ', width - kvp.Value.Length - 3) +"│");
Console.WriteLine("│" + new String(' ', width + 1) + "│");
Console.WriteLine("├" + new StringBuilder().Insert(0," ─",width/2).ToString() + " ┤");
Console.WriteLine("│ Which Option? " + new String(' ', width - 14) + "│");
Console.WriteLine("└" + new String('─', width + 1) + "┘");
Answer = Console.ReadLine();
foreach (KeyValuePair<string, string> kvp in this._options){
if (kvp.Key == Answer){ return kvp; }
Console.WriteLine("Invalid Option");
private int MaxOptionLength(){
foreach (KeyValuePair<string, string> kvp in this._options){
kvSize = kvp.Key.Length + kvp.Value.Length;
if (kvSize > max){ max = kvSize; }