Ken*_*Kin 1 c# unreachable-code
灵感来自问题
在我提出这个问题之前,我读过:
问题的挑战是
编写一个程序,该程序具有可访问的goto语句,但相应的标记语句无法访问 - Eric Lippert
一个可行的答案就像
// the 3 lines are not important but declare variable for afterwards use
var whateverException=new Exception("whatever exception");
var whateverAction=default(Action);
whateverAction=() => whateverAction();
Run Code Online (Sandbox Code Playgroud)
try {
goto whateverLabel; // (1) the goto is reachable
}
finally {
throw whateverException; // (3) because finally hijacks
}
whateverLabel: // (2) but the label is not really reached
whateverAction();
Run Code Online (Sandbox Code Playgroud)
我想知道在一个单线程程序中,它是唯一一个指向无法访问标签的可达goto吗?以下代码也被认为是可行的答案吗?
here:
int d=0, n=1/d;
goto here;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
242 次 |
| 最近记录: |