我在 C# 中做了一个 switch case 语句,它为用户提供了几个可供选择的选项。如果用户输入无效选项,我希望它再次运行(可能通过某种循环)。请帮助我,我相信这是非常基本的。
static void Main(string[] args)
{
int a,b,ch;
Console.WriteLine("Enter the value of a:");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the value of b:");
b = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter your choice : Addition:0 Subtraction:1 Multiplication :2 :");
ch = Convert.ToInt32(Console.ReadLine());
switch(ch)
{
case 0: {
Console.WriteLine("Addition value is :{0}", a + b);
break;
}
case 1:
{
Console.WriteLine("Subtraction value is :{0}", a - b);
break;
}
case 2:
{
Console.WriteLine("Multiplication value is :{0}", a * b);
break;
}
default:
{
Console.WriteLine("Invalid choice ");
goto switch(ch);
//please tell me what should i write here, it should go to the start of the switch case
}
case 4:
{
continue;
//please tell me what should i write here.it should come out of the loop show the result
}
}
}
}
}
}