.
Loading
.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Abhishek YadavRank #217 · 11.3K reputationPosted Jun 3, 2023, 3:11 PM EDT
Console.Write()is used to display output without a new line at the end, whileConsole.WriteLine()is used to display output with a new line at the endVishal JoshiRank #377 · 6.7K reputationPosted Jun 5, 2023, 3:45 AM EDT
In C# programming, Console.Write() and Console.WriteLine() is a method used to output text to the console window. The main difference between them lies in how they handle the newline character ('\n').
Deepak RawatRank #646 · 3.7K reputationPosted Jun 5, 2023, 6:50 AM EDT
In C#, both
Console.Write()andConsole.WriteLine()are methods used to display output to the console window. The main difference between them lies in how they handle line breaks.Sam HobbsRank #107 · 20.5K reputationPosted Jun 5, 2023, 3:56 PM EDT
I think it depends on options whether WriteLine adds just a Linefeed (10) or a Carriage Return (13) and Linefeed. In the following:
StringWriter sw = new StringWriter(); sw.WriteLine("Test"); sw.Close(); string s = sw.ToString(); Console.Write("{0} characters:", s.Length); foreach (char c in s) { Console.Write(" {0}", (int)c); } Console.WriteLine();The output is:
In other words, WriteLine added a Carriage Return (13) and Linefeed (10).
And a fiddle for that is at:
https://dotnetfiddle.net/iTjjkI