C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Also: If you are printing a string that already has a newline, you can use Console.Write for an entire line.
And: When you call WriteLine with no parameters, it only writes a newline. It always writes a newline.
C# program that uses Console.Write
using System;
class Program
{
static void Main()
{
Console.Write("One "); // <-- This writes the word.
Console.Write("Two "); // <-- This is on the same line.
Console.Write("Three"); // <-- Also on the same line.
Console.WriteLine(); // <-- This writes a newline.
Console.WriteLine("Four"); // <-- This is on the next line.
}
}
Output
One Two Three
Four
Note: If you concatenate strings before calling Console.Write, porting your code to another program may be more difficult.
string.ConcatAnd: Sometimes using format strings is desirable, but they can also make the program less readable.
string.Format