是否可以在c#中实现命令提示符命令历史记录 [英] Is it possible to implement like command prompt command history in c#

查看:70
本文介绍了是否可以在c#中实现命令提示符命令历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中实现一个概念,如命令提示符命令历史记录。

(在命令提示符中,如果我们按向上或向下箭头以前键入的命令将显示是否可以实现此概念c#application)

解决方案

是的。



具体如何取决于您的应用程序,但它最简单一个控制台应用程序...



尝试创建一个类级别的字符串列表,每次用户输入命令时,将其添加到底部。

然后,当他们按向上箭头键时,您可以返回列表,在命令行上逐一显示它们。


正如我们已经建议的那样原始,一个简单的列表就足够了。要获得更高级的方法(仅在您需要时),请查看命令设计模式 [ ^ ]。

I want to implement one concept in my application like command prompt command history.
(in command prompt if we press up or down arrow previously typed commands will display is it possible to implement this concept in c# application )

解决方案

Yes.

Exactly how is up to your application, but it's easiest for a console app...

Try creating a List of strings t class level, and each time your user enters a command, add it on teh bottom.
Then, when they press the up arrow key, you can move back through the list, showing them one by one on your command line.


As already suggested by our Original, a simple list could be enough. For a more advanced approach (only if you need it) have a look at Command Design Pattern[^].


这篇关于是否可以在c#中实现命令提示符命令历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆