Switch语句中的"default”case问题

cspml 2008-07-30 10:59:21

using System;
class Doloop
{
public static void Main()
{
string myChoice;
do
{
// Print A Menu
Console.WriteLine("My Address Book\n");
Console.WriteLine("A - Add New Address");
Console.WriteLine("D - Delete Address");
Console.WriteLine("M - Modify Address");
Console.WriteLine("V - View Addresses");
Console.WriteLine("Q - Quit\n");
Console.WriteLine("Choice (A,D,M,V,or Q): ");

// Retrieve the user's choice
myChoice = Console.ReadLine();
// Make a decision based on the user's choice
switch (myChoice)
{
case "A":
case "a":
Console.WriteLine("You wish to add an address.");
break;
case "D":
case "d":
Console.WriteLine("You wish to delete an address.");
break;
case "M":
case "m":
Console.WriteLine("You wish to modify an address.");
break;
case "V":
case "v":
Console.WriteLine("You wish to view the address list.");
break;
case "Q":
case "q":
Console.WriteLine("Bye.");
break;
default:
Console.WriteLine("{0} is not a valid choice", myChoice);
}

// Pause to allow the user to see the results
Console.Write("Press any key to continue...");
Console.ReadLine();
Console.WriteLine();
}
while (myChoice != "Q" && myChoice != "q");
// Keep going until the user wants to quit
}
}

这段代码在VS2008中被提示“控制不能从一个 case 标签(“default:”)贯穿到另一个 case 标签
请问这是怎么回事?
...全文
416 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cspml 2008-07-30
  • 打赏
  • 举报
回复
好了,感谢各位的帮助
zhouchenguang 2008-07-30
  • 打赏
  • 举报
回复
default:
……
break;
kenning 2008-07-30
  • 打赏
  • 举报
回复
少了break;
yangxueke 2008-07-30
  • 打赏
  • 举报
回复
case "D":
case "A"
case "V
.....

少break;
我姓区不姓区 2008-07-30
  • 打赏
  • 举报
回复
default最后没有break
maddemon 2008-07-30
  • 打赏
  • 举报
回复
default下加个 break;

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧