switch case in C# with enum code example
Example 1: enum switch menu c#
enum Menu
{
Students_Detail = 1,
Display = 2,
Exit = 3
}
static void Main(string[] args)
{
Console.WriteLine("Please select a menu option");
Console.WriteLine("1. Students Detail");
Console.WriteLine("2. Display");
Console.WriteLine("3. Exit");
int pick = Convert.ToInt32(Console.ReadLine());
Menu menuChoice = new Menu();
menuChoice = (Menu)pick;
switch (pick)
{
case 1:
break;
case 2:
break;
case 3:
break;
default:
break;
}
}
Example 2: c# enumerate switch
public enum Operator
{
PLUS, MINUS, MULTIPLY, DIVIDE
}
enum Operator op;
op = Operator.PLUS;
switch(op)
{
case Operator.PLUS:
{
break;
}
case Operator.MULTIPLY:
{
break;
}
default: break;
}