有没有更好的替代 Console.ReadKey() 的方法?
大多数编程书籍都会告诉您使用 Console.ReadKey() 来暂停控制台,但是有更好的选择吗?
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
Most programming books will tell you to use Console.ReadKey() to pause the console, but is there a better alternative?
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您实际上还没有告诉我们您希望实现什么目标。
如果您希望停止输出直到用户选择继续,那么您实际上不会比使用
Console.ReadKey
等待按键更好。代码>.如果您只想暂停输出一段时间,可以使用
Thread.Sleep
方法,该方法不需要任何人工干预。You haven't actually told us what you wish to achieve.
If you wish to stop the output until the user chooses to continue, then you're not really going to get much better than just waiting for a key to be pressed using
Console.ReadKey
.If you just want to pause the output for a certain amount of time, you can use the
Thread.Sleep
method, which doesn't require any human intervention.Console.ReadLine() 怎么样:)
How about Console.ReadLine() :)
做同样的事情
does the same thing