开发者

Set what Console.ReadKey gets with Console.SetIn?

I know you can do Console.SetIn(new StringReader("new input"开发者_StackOverflow中文版)); and then Console.ReadLine(); will return "new input" but is there a way to do this for Console.ReadKey()?


No, Console.ReadKey() uses the native console API, ReadConsoleInput() to read input. You can't redirect that.

Other than by the obvious way, write a public static method that calls ReadKey() unless you want to return something else.


I believe you would rather want Console.Read() as ReadKey waits for a keystroke while Read just reads the next character.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜