gpt4 book ai didi

C# 拼图 : Reachable goto pointing to an unreachable label

转载 作者:太空狗 更新时间:2023-10-30 00:09:25 26 4
gpt4 key购买 nike

这是 Eric Lippert 来自 this post 的评论:

Now that you know the answer, you can solve this puzzle: write me a program in which there is a reachable goto which goes to an unreachable label. – Eric Lippert Jul 17 at 7:17

我无法创建将可访问的 goto 指向无法访问的标签的代码。这可能吗?如果是,C# 代码会是什么样子?

注意:我们不要讨论“goto”有多糟糕等等。这是一个理论练习。

最佳答案

我原来的回答:

    try
{
goto ILikeCheese;
}
finally
{
throw new InvalidOperationException("You only have cottage cheese.");
}
ILikeCheese:
Console.WriteLine("MMM. Cheese is yummy.");

这里没有编译器警告。

    bool jumping = false;
try
{
if (DateTime.Now < DateTime.MaxValue)
{
jumping = (Environment.NewLine != "\t");
goto ILikeCheese;
}

return;
}
finally
{
if (jumping)
throw new InvalidOperationException("You only have cottage cheese.");
}
ILikeCheese:
Console.WriteLine("MMM. Cheese is yummy.");

关于C# 拼图 : Reachable goto pointing to an unreachable label,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1167666/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com