how to call “ static void Main(string[] args) ”in the class again

后端 未结 5 435
渐次进展
渐次进展 2021-01-23 20:53

i am new in C# and working on Console Applications now a days i wrote the following code :

Program.cs

using System;
using System.Collect         


        
5条回答
  •  滥情空心
    2021-01-23 21:25

    You realy should not use a goto or call your Main again (recursion), do while is a better solution to repeat your logic muliple times:

        string selectedOption;
        do {
            Write();
            string name = Console.ReadLine();
            Write();
            string name1 = Console.ReadLine();
            Write();
            string name2 = Console.ReadLine();
            Write();
            string name3 = Console.ReadLine();
    
             Console.WriteLine("{0}, {1}, {2}, {3}",name,name1,name2,name3);
    
             Console.WriteLine("enter \"y\" to restart the program and \"n\" to exit the Program");
             selectedOption = Console.ReadLine();
          } while (selectedOption == "y")
          Console.ReadKey();
    

提交回复
热议问题