C# 在执行命令后,如何重新开始代码?

C# 在执行命令后,如何重新开始代码?,c#,console-application,C#,Console Application,我需要在我正在制作的游戏中制作3个区域,并且我需要重置我的代码,以便您可以在区域之间移动。是否有命令或代码可以执行此操作 它需要在你想离开区域后的一个窗口上完成 if (choice == 2) { Console.WriteLine("you live"); } Console.WriteLine("you left the temple and went towards the forest"); // the code starts over form the beginning

我需要在我正在制作的游戏中制作3个区域,并且我需要重置我的代码,以便您可以在区域之间移动。是否有命令或代码可以执行此操作

它需要在你想离开区域后的一个窗口上完成

if (choice == 2)
{
    Console.WriteLine("you live");
}

Console.WriteLine("you left the temple and went towards the forest");
// the code starts over form the beginning
我希望它在一个区域结束后重新启动代码。

我建议在while循环中使用switch case,但下面我添加了一个可能的解决方案,其中包含一个简单的if语句(或者else if,如果您愿意)


听起来你只是需要一个循环。当用户选择2时,这会多次打印“你还活着”和“你离开了神庙…”。@JessedeWit我认为这是故意的,但我可能弄错了。我的观点是你必须更新循环顶部的选择,以避免无限循环。
while (true) 
{
if (choice == 2) 
{
    Console.WriteLine("you live");
}
//Have a specific number for the user to input when they want to exit the program
if (choice == 3) 
{
    //break from the while loop
    break;
}
Console.WriteLine("you left the temple and went towards the forest");
// the code starts over form the beginning
}