更新:2007 年 11 月
错误消息
控制不能从一个 case 标签(“label”)贯穿到另一个 case 标签
对于包含一个或多个语句并且后跟另一个 case 语句的 case 语句,必须使用以下关键字之一显式终止:
return
goto
break
throw
continue
如果要实现“贯穿”行为,请使用 goto case #。有关更多信息,请参见 switch(C# 参考)
下面的示例生成 CS0163:
// CS0163.cs
public class MyClass
{
public static void Main()
{
int i = 0;
switch (i) // CS0163
{
case 1:
i++;
// uncomment one of the following lines to resolve
// return;
// break;
// goto case 3;
case 2:
i++;
return;
case 3:
i = 0;
return;
}
}
}