【问题标题】:How would you go about refreshing your application once you have pressed any key? C#按下任意键后,您将如何刷新应用程序? C#
【发布时间】:2017-01-19 16:24:22
【问题描述】:

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

到目前为止,我有:

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

我希望这能澄清我的问题!

非常感谢 - 丹

【问题讨论】:

  • “刷新”您的 C# 应用程序是什么意思?
  • 应用程序在不关闭/重新打开的情况下自行重启 - 这可能吗?
  • 我猜这是对编程课的一些介绍。将整个内容包装在while(refresh) loop 循环中,并将刷新定义为循环外的布尔值并初始化为true。仅当用户在 while 块底部处理某些特定键时才将刷新设置为 false,在该块底部您定义了上述 2 行。
  • 请澄清您的具体问题或添加其他详细信息以准确突出您的需要。正如目前所写的那样,很难准确地说出你在问什么。请参阅How to Ask 页面以获得澄清此问题的帮助。

标签: c# console console-application


【解决方案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;
            }
        }      

【讨论】:

    猜你喜欢
    • 2022-01-17
    • 2015-11-05
    • 1970-01-01
    • 2014-05-01
    • 1970-01-01
    • 2015-11-17
    • 2013-04-19
    • 2013-10-24
    • 2018-09-30
    相关资源
    最近更新 更多