Console I/O
Learn to write to console and read from console.
We'll cover the following...
Console output
We’ve already worked with console input and output and written several statements that print to the console. This lesson provides several exercises for us to consolidate this knowledge.
There are essentially two methods that are most important if we need to output to the console:
- The
Console.Write()
method prints to the console and keeps the cursor on the same line. - The
Console.WriteLine()
method prints to the console and moves the cursor to the next line.
To understand this difference more clearly, let’s consult the following code snippets:
Press + to interact
using System;class Program{static void Main(){// Because the cursor stays on the same line,// we have the text printed on the same lineConsole.Write("Hello");Console.Write("World");}}
As we can see, despite the fact that ...