Console.Read()
accepts values into the input stream until Enter is pressed. Each subsequent call to
Console.Read()
reads a
single character from that input.
Console.ReadLine()
retrieves a full line from the input stream. Do you see what's going wrong?
If you type in "XYZ" and press Enter at
Console.Read()
you have "YZ<enter>" in the input stream with
r
set to X. Then
Console.ReadLine()
picks up the remaining "YZ<enter>" and the program terminates. This quirk is why MSDN recommends not to use
Console.Read()
favoring
Console.ReadLine()
and
Console.ReadKey()
instead.
This is easily demonstrated with the following code:
int r = Console.Read();
Console.WriteLine(Console.ReadLine());
Console.ReadKey();
Typing "XYZ" then Enter will yield the following output:
XYZ
YZ