Using the Console

Writing to the Console output using Console.WriteLine

All messages that you want to display to the user in the Console are printed using the various Console.WriteXXX methods that form part of the Console API.

As with our previous example, we can see how we can use Console.WriteLine to print "Hello World" to the output. Feel free to play with the code to see how you can write more information to the output.

using System; public class Program { ...

 

Available write operations

The Console API provides various methods for writing information, let's look at a couple of the method signatures.

void Write(string);
void WriteLine(string);

Both operations write whatever string argument we pass in to the screen, but the latter operation WriteLine also writes a line-terminator after each call too.

You can get more information on the Write methods in the "Deep Dive" section of this tutorial.

 

Useful Tip

 

If you're using Visual Studio or .NET Fiddle, as you type Console., you'll be prompted with suggestions to help you finish your statements. This feature is called Intellisense.

 

Page 3 of 12