繁体   English   中英

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

[英]How would you go about refreshing your application once you have pressed any key? C#

我目前正在创建一个程序; 我不知道如何在按下某个键后刷新应用程序。

到目前为止,我有:

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) 中的操作运行,消息; 出现“按任意键刷新” - 之后我希望它在按下某个键后刷新应用程序!

我希望这能澄清我在问什么!

非常感谢 - 丹

如果我正确理解您想要完成的任务,这可能会有所帮助。

        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;
            }
        }      

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM