Console.Read() - Please help C# newbie
Hi,
I want to create menu driven condole application
(1. Do this, 2. Do that, 3. Exit)
I have a stranger problem with Console.Read()
I'm reading a character in a loop using Console.Read()
and displaying it using Console.Write()
VB Code:
public static void Test()
{
int i;
char c;
while (true)
{
i = Console.Read ();
c = (char) i;
Console.WriteLine ("Echo: {0}", c);
}
}
When I press 5<Enter>, then 9<Enter> I should be getting this:
Instead, I'm getting this:
VB Code:
5
Echo: 5
Echo: // remembers char 13 - line feed
Echo: // remembers char 10 - new line
9
Echo: 9
Echo: // remembers char 13 - line feed
Echo: // remembers char 10 - new line
After stepping through the code I realized that
the Console.Read() remembers the enter key as well (char 13 and 10)
that's why the two empty echos after the actual number.
How can I solve this? Flash the buffer?
I need to use Console.Read() for reading single digits.
Any help appreciated.
Re: Console.Read() - Please help C# newbie
Re: Console.Read() - Please help C# newbie
Yeah,
I wanted to do this with the .Read() but I give up (spend too much time on it although I learned few things doing so).
I did my menu using ReadLine() instead and it works well.