如何离开课堂

Jho*_*hon -1 c#

我创建了一个小项目.这是它:

class Program
{
   public static void Main()
    {
        Console.WriteLine("Welcome");
        Console.WriteLine("1 to go to Data Files ");
        Console.WriteLine("type quit to exit");
        string input = Console.ReadLine();
        if (input == "1")
        {
            Data go = new Data();
        }
        else if (input == "quit")
        {

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当用户输入quit时.我希望我的程序退出.请帮助我的人

Sea*_*ean 5

你只需要这样的东西:

else if (input == "quit")
{
  return;
}
Run Code Online (Sandbox Code Playgroud)

更新:根据您的评论,我认为您正在寻找这样的事情:

class Program
{
   public static void Main()
    {
        while(true)
        {
                Console.WriteLine("Welcome");
                Console.WriteLine("1 to go to Data Files ");
                Console.WriteLine("type quit to exit");
                string input = Console.ReadLine();
                if (input == "1")
                {
                    Data go = new Data();
                }
                else if (input == "quit")
                {
                   return;
                }
                else
                {
                  Console.WriteLine("invalid option");
                }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)