I'm learning C# for one of my classes and for my assignment I need to get user input from the console.
In my program I have:
choice = (char)System.Console.Read();
Later on in the program I use
if (System.Console.ReadLine() == "y")
to get input from the user.
The second statement gets skipped when I run the program. I'm guessing that the System.Console.Read() is leaving a newline in the stream. In C/C++, there's fflush() and cin.ignore(). What is the equivalent function in C#?
I know that it's probably easier for me to use ReadLine() or ReadKey(), but I'm just curious as to how to use Read() with newlines
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…