小编Har*_*isk的帖子

C#执行goto语句后如何返回上一步?

这是我的代码:

private void Mymethod()
{
    if(animal == "Dog")
    {
        goto LabelMonsters;
    }

    //return here after goto LabelMonsters executes
    if (animal == "Cat")
    {
        goto LabelMonsters;
    }

    //another return here after goto LabelMonsters executes
    if (animal == "Bird")
    {
        goto LabelMonsters;
    }

    //Some long codes/execution here.
    return;

    LabelMonsters:
    //Some Code
}
Run Code Online (Sandbox Code Playgroud)

在我的示例中,我有几个if语句,在第一次执行goto语句之后,我必须返回到我的方法下的下一步.我试过继续但不工作.执行必须持续到最后.

c#

0
推荐指数
1
解决办法
208
查看次数

标签 统计

c# ×1