For testing purposes, you may create a simple console application that allows writing to and reading from a console window.
The Console.ReadLine method reads the next line’s worth of characters, storing the result in a string. The user can enter some text and then press the Enter key. When the user presses Enter, whatever they typed on that line is stored in a variable of type string.
1 2 3 4 5 6 7 | while (true){ <span class="skimlinks-unlinked">Console.Write</span>(": "); string nextLine = Console.ReadLine(); Console.WriteLine("[{0}]", nextLine);} |
You can also use the Console.Read method to read a single character. The characters are not read until the user presses Enter.
In the example below, the user types the letters a, and b and then presses Enter. The two calls to Console.Read are then executed, storing the ASCII values of the characters entered.
1 2 3 4 5 6 | int char1 = <span class="skimlinks-unlinked">Console.Read</span>();int char2 = <span class="skimlinks-unlinked">Console.Read</span>();<span class="skimlinks-unlinked">Console.Write("{0</span>} {1}", char1.ToString(), char2.ToString()); |

