C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Note: When the Read method is first called, it blocks execution waiting for the input to be sent by the terminal window.
Finally: It returns when the input is final. Then, you must call it in a loop to read the entire remaining buffer.
Example: The conditional expression here continues until zero is received from Console.Read—this occurs at the end of the input.
WriteLine: The program outputs the integer representation and the character representation of each value in the buffer.
ConsoleEnvironment.NewLineC# program that uses Console.Read method
using System;
class Program
{
static void Main()
{
// This program accepts console input.
// ... When the enter key is pressed,
// the Read method returns the first time.
// ... Then, each call to Read accesses one
// further character from the input.
int result;
while ((result = Console.Read()) != 0)
{
Console.WriteLine("{0} = {1}", result, (char)result);
}
}
}
Output
dotnetCodex
100 = d
111 = o
116 = t
110 = n
101 = e
116 = t
112 = p
101 = e
114 = r
108 = l
115 = s
13 =
10 =