【发布时间】: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