Why Doesn't Read() work as Expected?
c#, visual-studio, visual-studio-2008
Solution
//Program waits for [Enter] key. Why?
The Read method blocks its return while you type input characters; it terminates when you press the Enter key. Pressing Enter appends a platform-dependent line termination sequence to your input (for example, Windows appends a carriage return-linefeed sequence).
//Program does not wait for a key press. Why?
Subsequent calls to the Read method retrieve your input one character at a time [without blocking]. After the final character is retrieved, Read blocks its return again and the cycle repeats.
http://msdn.microsoft.com/en-us/library/system.console.read.aspx
Problem
I'm using Visual Studio 2008 for C#. I can't understand why this simple code does not work as expected. Any ideas? Thanks! ``` using System; namespace TryRead { class Program { static void Main() { int aNumber; Console.Write("Enter a single character: "); aNumber = Console.Read(); **//Program waits for [Enter] key. Why?** Console.WriteLine("The value of the character entered: " + aNumber); Console.Read(); **//Program does not wait for a key press. Why?** } } } ```