switch(面试)
public static void Output() { int i = 10; while (i!=0) { i--; switch (i) { case 1: Console.WriteLine(i.ToString()); break; case 2: Console.WriteLine(i.ToString()); break; default: Console.WriteLine(i.ToString()); return; } } }
结果为9
至于在switch中使用break还是return的结果是:
break是直接退出switch语句;
return是退出函数;