我正在为我的一门类(class)和作业学习 C#,我需要从控制台获取用户输入。
在我的程序中我有:
choice = (char)System.Console.Read();
稍后在我使用的程序中
if (System.Console.ReadLine() == "y")
获取用户的输入。
当我运行程序时,第二条语句被跳过。我猜 System.Console.Read() 在流中留下一个换行符。在 C/C++ 中,有 fflush() 和 cin.ignore()。 C# 中的等效函数是什么?
我知道我可能更容易使用 ReadLine() 或 ReadKey(),但我只是好奇如何使用 Read() 换行
最佳答案
这是我对 fflush 的等价物:
while (Console.KeyAvailable)
Console.ReadKey(true);
关于c# - 冲洗 System.Console.Read(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7302544/