C#: Analysis of the difference between write() and writeline()

Both write() and writeline() are methods provided by system.console, which are mainly used to display the output stream from the specified output device (screen by default).
the differences between the two methods are as follows:

The console. Writeline() method outputs the string to be output together with the newline control character. When the next statement is executed, the cursor will move to the next line of the current output string.
as for the console. Write() method, the cursor will stop after the last character of the output string in C # tutorial, and will not move to the next line.

The difference between write() and writeline()

All the methods provided by system.console
are displayed on the screen
write() does not wrap after it is displayed, and writeline() wraps
code examples

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace The difference between WriteLine and Write
WriteLine
class Program
{
static void Main(string[] args)
{
//WriteLine output with mouse at the beginning of the next line
//Write output does not start a new line
System.Console.WriteLine("First WriteLine Line");
System.Console.WriteLine("Second WriteLine Line");
 
System.Console.Write("First Write Line");//Instead of starting a new line after the First Write Line, the output is directly followed by the Second Write Line
System.Console.Write("Second Write Line");
 
//passing parameters
System.Console.WriteLine("\nWriteLine:Parameter={0}", 123);
System.Console.Write("Write:Parameter={0}", 456);
System.Console.ReadKey();
}
}
}
output

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

Here is the article about the difference between write() and writeline() in C #. For more information about CSharp write and writeline, please search the previous articles of script home or continue to browse the following related articles. I hope you can support them in the future


Read More: