是否可以在C#中刷新控制台应用程序? [英] Is it possible to refresh the console application in c#?
本文介绍了是否可以在C#中刷新控制台应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以像Windows应用程序一样在c#中刷新控制台应用程序?或者有相同目的的替代方法?请告诉我该怎么做?
Hi,
Is it possible to refresh the console application in c# like windows application?Or is there any alternative for the same purpose?Kindly tell me how to do that?
Thanks.
推荐答案
否-控制台应用程序没有Windows应用程序那样的Application对象.
您可以通过以下方式复制效果:
No - a Console application does not have an Application object in teh same way that a Windows one does.
You can duplicate the effect though:
static void Main(string[] args)
{
while (RunMyApp(args))
{
}
}
static bool RunMyApp(string[] args)
{
...
return true; // Restart
...
return false; // End program
}
您可以清除屏幕.
尝试
Well you can clear the screen.
Try with
Console.Clear();
方法.
更新:
看到其他人重播后,也许我问错了.
检查此示例:
method.
UPDATE:
after seeing other peoples replay maybe I got a question wrong.
Check this example:
class Program
{
static void Main(string[] args)
{
Console.Clear();
bool done = false;
while (!done)
{
ShowMenu();
ConsoleKeyInfo keyHit = Console.ReadKey(true);
Console.Clear();
switch (keyHit.KeyChar)
{
case '1':
SimpleArraySort();
break;
case '2':
SimpleListSort();
break;
case '5':
PerformanceTest();
break;
case '9':
done = true;
break;
default:
Console.WriteLine("Please enter a valid option. \r\n");
continue;
}
}
}
}
干杯
Cheers
可能是您正在说的SetCursorPosition
...
http://stackoverflow.com/questions/5435460/console- application-how-to-update-the-display-with-flicker [
May beSetCursorPosition
is what you are talking...
http://stackoverflow.com/questions/5435460/console-application-how-to-update-the-display-without-flicker[^]
这篇关于是否可以在C#中刷新控制台应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文