SoFunction
Updated on 2025-03-08

Analysis of the difference between Write and WriteLine in C#

Write() and WriteLine() are both provided methods, and the two main methods are used to display the output stream from the specified output device (default is the screen).
The difference between the two sides is

() method is to output the string to be output together with the newline control characters. When the second statement is executed, the cursor will move to the next line of the current output string.
As for the() method, the cursor will stop after the last character of the output string and will not move to the next line.

The difference between Write() and WriteLine()

  • All methods provided
  • It's all displayed on the screen
  • Write() will not wrap the line after displaying it, WriteLine() will wrap the line.

Code Example

using System;
using ;
using ;
using ;
using ;

namespace WriteLineandWriteThe difference
{
class Program
{
static void Main(string[] args)
{
//The mouse is displayed at the beginning of the next line after the WriteLine output//Write output does not start a new line("First WriteLine Line");
("Second WriteLine Line");

("First Write Line");//There is no new line after the First Write Line, and the Second Write Line is output immediately.("Second Write Line");

//passing parameters
("\nWriteLine:Parameter={0}", 123);
("Write:Parameter={0}", 456);
();
}
}
}

Output

First WriteLine Line
Second WriteLine Line
First Write LineSecond Write Line
WriteLine:Parameter=123
Write:Parameter=456

This is the end of this article about the difference between Write() and WriteLine() in C#. For more related contents of csharp write and writeline, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!