static void Main(string[] args) { MenuCollection menus = MenuGenerator.CreateMenuCollection(); menus.ShowMenu(1); Console.ReadKey(); }
static void Main(string[] args) { // build a collection of menus // can have as deep a structure as you like // give each menu a unique integer MenuId // link to other menus by setting HasSubMenu to true, and the SubMenuId to the MenuId of the menu you wish to link to // or, set HasSubMenu to false, and have an Action performed when the menuitem is selected MenuCollection collection = new MenuCollection() { Menus = { new Menu() { MenuId = 1, MenuItems = { new MenuItem() { Text = "Go to sub menu", HasSubMenu = true, SubMenuId = 2 }, new MenuItem() { Text = "Print Action", HasSubMenu = false, Action = () => { Console.WriteLine("I printed from an action"); } } } }, new Menu() { MenuId = 2, MenuItems = { new MenuItem() { Text = "Sub menu option 1", HasSubMenu = false, Action = () => { Console.WriteLine("Printed from a sub menu"); } }, new MenuItem() { Text = "Back to the top menu", HasSubMenu = true, SubMenuId = 1 } } } } }; collection.ShowMenu(1); Console.ReadLine(); }