In C#, Console.Write sends text to the console’s standard output stream and leaves the cursor on the same line. The next print continues right after the last character.
Use Write for prompts like "Name: " so the user types on the same line, or when you want several values in one row. Prefer WriteLine when each message should end on its own line.
This is a static member of System.Console. You call it with the type name, such as Console.Write(...). Console is the everyday API for reading from standard input and writing to standard output in C# console apps.
Syntax
Call Console.Write with a string, a value, or a format string and arguments.
WriteLine does the same printing job but always ends with a newline. Mixing Write and WriteLine is common for prompts.
Library declarations
C#
public static void Write(string? value);
public static void Write(string format, params object?[]? arg);
public static void Write(int value);
// many overloads for common types
Parameters
Parameter
Description
value
Text or a value to print (many typed overloads).
format
Optional format string with {0}, {1}, … placeholders.
arg
Values inserted into the format string.
Return Value
Return Value
Description
void
Nothing is returned. Text goes to the current output writer (Console.Out).
C# Examples
Example 1 — Print Without a Newline
Two Write calls stay on one line; a final WriteLine ends it.
C#
using System;
class Program {
static void Main() {
Console.Write("Hello");
Console.Write(", ");
Console.Write("world");
Console.WriteLine("!");
}
}
Output
Hello, world!
How It Works
No newline yet. Each Write appends on the same line.
Pieces join."Hello", ", ", and "world" become one phrase.
Finish the line.WriteLine("!") prints ! and moves to the next line.
Cursor position. After Write alone, the next print continues immediately after.
Example 2 — Ask on the Same Line
Show a prompt with Write, then read a name with ReadLine.
C#
using System;
class Program {
static void Main() {
Console.Write("Enter name: ");
string name = Console.ReadLine() ?? "";
Console.WriteLine("Hello, " + name + "!");
}
}
Output
Enter name: Ada
Hello, Ada!
How It Works
Same-line prompt.Write leaves the cursor after the colon so typing looks natural.
Sample input. The sample output shows the user typing Ada and pressing Enter.
Null-safe.?? "" treats end-of-file null as an empty string.
Greeting line.WriteLine prints the full hello message on its own line.
Example 3 — Format Values Inline
Use a format string to print numbers without starting a new line each time.
C#
using System;
class Program {
static void Main() {
int a = 3, b = 7;
Console.Write("a={0} ", a);
Console.Write("b={0} ", b);
Console.WriteLine("sum={0}", a + b);
}
}
Output
a=3 b=7 sum=10
How It Works
Placeholders.{0} is replaced by the next argument.
Trailing space. Spaces in the format keep values readable on one row.
Last call.WriteLine prints the sum and ends the line.
One row of facts. All three pieces appear together in the output.
Frequently Asked Questions
No. The cursor stays on the same line. Use WriteLine when you want a newline.
Use Write for prompts and for several values on one line. Use WriteLine for complete messages.
Yes. There are overloads for int, double, and many other types, plus format-string overloads.
To Console.Out, the standard output writer. SetOut can redirect it.
It is similar in spirit: print text. Format strings use {0} style placeholders, not %d.