IMenu is an interface in C# that allows the creation of menus with options for a console application. It is part of the System.Console class library.
Example 1: In this example, a simple menu with three options is created using the IMenu interface. When the user selects an option, the relevant action is performed.
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ConsoleApp { class Program { static void Main(string[] args) { IMenu menu = new SimpleMenu(); int choice = menu.Run(); switch (choice) { case 1: Console.WriteLine("Option 1"); break; case 2: Console.WriteLine("Option 2"); break; case 3: Console.WriteLine("Option 3"); break; default: Console.WriteLine("Invalid choice"); break; } Console.ReadKey(); } }
interface IMenu { int Run(); }
class SimpleMenu : IMenu { public int Run() { Console.WriteLine("1. Option 1"); Console.WriteLine("2. Option 2"); Console.WriteLine("3. Option 3"); Console.Write("Enter choice: "); int choice = int.Parse(Console.ReadLine()); return choice; } } }
Example 2: In this example, the IMenu interface is used to create a menu with options to add, delete or update records in a database. The relevant action is performed when the user selects an option.
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ConsoleApp { class Program { static void Main(string[] args) { IMenu menu = new DBMenu(); int choice = menu.Run(); switch (choice) { case 1: Console.WriteLine("Add record"); break; case 2: Console.WriteLine("Delete record"); break; case 3: Console.WriteLine("Update record"); break; default: Console.WriteLine("Invalid choice"); break; } Console.ReadKey(); } }
interface IMenu { int Run(); }
class DBMenu : IMenu { public int Run() { Console.WriteLine("1. Add record"); Console.WriteLine("2. Delete record"); Console.WriteLine("3. Update record"); Console.Write("Enter choice: "); int choice = int.Parse(Console.ReadLine()); return choice; } } }
Package/Library: System.Console class library.
C# (CSharp) IMenu - 45 examples found. These are the top rated real world C# (CSharp) examples of IMenu extracted from open source projects. You can rate examples to help us improve the quality of examples.