If语句
Switch语句
注:从 C# 7.0 开始 switch 表达式已支持任何非 null 表达式。
//需求:80-100:A;60-79:B;40-59:C;0-39:D;其他:Error;
int score = 101;
switch (score/10)
{
case 10:
if (score==100)
{
goto case 9;
}
else
{
goto default;
}
case 9:
case 8:
Console.WriteLine("A");
break;
case 7:
case 6:
Console.WriteLine("B");
break;
case 5:
case 4:
Console.WriteLine("C");
break;
case 3:
case 2:
case 1:
case 0:
Console.WriteLine("D");
break;
default:
Console.WriteLine("Error!");
break;
}
Code Snippet
- Ctrl + L 剪切一整行