按下任何键后,如何刷新应用程序? C#

时间:2017-01-19 16:24:23

标签: c# console console-application

我正在创建一个程序;在按下某个键后,我无法弄清楚如何刷新应用程序。

到目前为止,我有:

Console.WriteLine("Press Any Key To Refresh");

Console.ReadKey();

完整代码块

class Program
{
    static void Main(string[] args) 
    { 
        int userInput;
        DirectoryInfo folderInfo = new DirectoryInfo("C:\\Windows");
        FileInfo[] files = folderInfo.GetFiles();


        Console.WriteLine("Welcome To File Manager");

        Console.WriteLine("");

        Console.WriteLine("Current Folder: C:\\Windows");

        Console.WriteLine("");

        Console.WriteLine("Please Select An Opion Between 1 To 4:"); // Displays Options for Main Menu. 
        Console.WriteLine("1. ");
        Console.WriteLine("2. ");
        Console.WriteLine("3. ");
        Console.WriteLine("4. ");
        userInput =int.Parse(Console.ReadLine());
        { 
            if (userInput == 1)   
            {
                Console.WriteLine("Files in C:\\Windows:");
                for (int index = 0; index < files.Length; index++) // Lists The Files Within The Speficied Folder C:\\Windows - Also Assigns Numerical Value To Each File. 
                {
                    Console.WriteLine("{0}" , index + ". " + 1 + files[index].Name + "   (" +(files[index].Length) + ")"); 


                }
                Console.WriteLine("Press Any Key To Return To Main Menu");
                Console.ReadKey();



            }

            else if (userInput == 2)
            {
                // code for option 2 
            }
            else if (userInput == 3)
            {
                // Code for option 3
            }
            else if (userInput == 4)
            {
               // Closes Application.
            }
        } while (userInput != 4);

一旦选项(1)中的操作已经运行,该消息;出现“按任意键刷新” - 之后我想按一下键刷新应用程序!

我希望这能澄清我的要求!

非常感谢 - 丹

1 个答案:

答案 0 :(得分:-1)

如果我理解你想要完成的事情,这可能会有所帮助。

        bool isClicked = true;

        while(isClicked)
        {
            Console.WriteLine("Please Select An Opion Between 1 To 4:");
            int userInput = int.Parse(Console.ReadLine());

            switch (userInput)
            {
                case 1:
                    Console.WriteLine("Press Any Key To Return To Main Menu");
                    Console.ReadKey();

                    //isClicked = false;        // Used to suspend the operation

                    break;
                case 2:
                    // code for option 2 
                    break;
                case 3:
                    // code for option 3
                    break;
                case 4:
                    // code for option 4 
                    break;
                default:
                    Console.WriteLine("Error occured");
                    break;
            }
        }