代码如下:
using System;
class Switch_Test
{
static void Main()
{
Console.WriteLine("box sizes: 1=Small 5=Medium 10=Large");
Console.Write("请选择: ");
string s = Console.ReadLine();
int n = int.Parse(s);
int cost = 0;//初始化数据
switch (n)
{
case 1:
cost += 1;
break;
case 5:
cost += 5;
goto case 1;
case 10:
cost += 10;
goto case 1;
default:
Console.WriteLine("无效的输入. 请选择1, 5, or 10.");
break;
}
Console.WriteLine("Thank you !你的花费={0}", cost);
}
}