Write and WriteLine: What is the difference?

The new line character is the basis for the difference between the Write() and WriteLine() methods. The Write() method does not supply a new line character but instead shows the output. The WriteLine() method shows the results and appends a new line character to the string.

Write Method

The ‘Console’ class, which is located under the System namespace, contains the Write function. Applications that read and write characters to and from the console can use the Console class to get the bare minimum of support. Without inserting a new line character, the write() method displays one or more values on the screen. This indicates that any additional output will print on the same line.

Example of Write() in C#


Car Bus Truck

WriteLine Method

The System namespace’s ‘Console’ class also contains the WriteLine function. With a new line character added at the end, the WriteLine method prints one or more objects on a single line. This means that each new line of output will now be printed.

Example of WriteLine() in C#



Key Difference

When printing one or more objects on a single line without adding a new line character at the end, use the Write method. After printing the output, the WriteLine function adds a new line character. The cursor stays on the same line in the Write method while it goes to the next in WriteLine.