[英]how to check for multiple switch statement in c#
我需要檢查switch語句中的多個語句來評估
int a=5;
switch(a)
{
case 4,5:
console.write("its from 4 to 5);
break;
}
你想做:
case 4:
case 5:
//Code goes here.
break;
請記住,雖然C#不允許通過,所以你不能這樣做:
case 4:
//Do some stuff here
//fall through to 5
case 5:
//Code goes here.
break;
在c#中你堆棧的情況是這樣的:
case 4:
case 5:
//do something
break;
case 6:
//do something
等等
這允許您為1個值執行多個案例。
int a=5;
switch(a)
{
case 4:
// Do work here
goto case 5;
case 5:
console.write("its from 4 to 5);
break;
}
要么
這是一個案例兩個標簽。
switch(a)
{
case 4:
case 5:
console.write("its from 4 to 5);
break;
}
這是怎么回事..
int a=5;
switch(a)
{
case 4:
case 5:
console.write("its from 4 to 5);
break;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.