灵感来自问题
在我问这个问题之前,我读过:
题目中的挑战是
write a program which has a reachable goto statement but the corresponding labelled statement is unreachable - 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();
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();
我想知道在单线程程序中,是不是只有一个可达的goto指向一个不可到达的标签?以下代码是否也被认为是可行的答案?
here:
int d=0, n=1/d;
goto here;
最佳答案
finally
-blocked goto
技巧实际上是获得针对不可到达标签的可到达 goto 的唯一方法。
关于c# - 这是唯一指向无法访问标签的可访问 goto 的情况吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15213116/