csharp C#菜单使用SWITCH功能CASE BREAK

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp C#菜单使用SWITCH功能CASE BREAK相关的知识,希望对你有一定的参考价值。

switch (selection)
{
case 1 :
handleCasement ();
break ;
case 2 :
handleStandard () ;
break ;
case 3 :
handlePatio () ;
break ;
default :
Console.WriteLine ( "Invalid number" ) ;
break ;
}


The switch construction takes a value which it uses to decide which option to
perform. It executes the case which matches the value of the switch variable. Of
course this means that the type of the cases that you use must match the switch
selection value although, in true C# tradition, the compiler will give you an error if you
make a mistake. The break statement after the call of the relevant method is to stop
the program running on and performing the code which follows. In the same way as
you break out of a loop, when the break is reached the switch is finished and the
program continues running at the statement after the switch.

Another useful feature is the default option. This gives the switch somewhere to go
if the switch value doesn't match any of the cases available; in our case (sorry!) we put
out an appropriate message.

以上是关于csharp C#菜单使用SWITCH功能CASE BREAK的主要内容,如果未能解决你的问题,请参考以下文章

switch case语句总执行第一个case

c语言case

switch是啥意思

switch case的用法

c语言 switch的用法

switch语句 switch语句的相关知识