C# Console Write() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Console

Definition

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.

C#
Console.Write("Hello");
Console.Write(" score={0}", 95);
Console.Write(42);
CallWhat it does
Console.Write("Hi")Prints text; cursor stays on the same line.
Console.Write("x={0}", 3)Formats and prints without a newline.
Console.Write(42)Prints the number as text.

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

ParameterDescription
valueText or a value to print (many typed overloads).
formatOptional format string with {0}, {1}, … placeholders.
argValues inserted into the format string.

Return Value

Return ValueDescription
voidNothing 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("!");
    }
}

How It Works

  1. No newline yet. Each Write appends on the same line.
  2. Pieces join. "Hello", ", ", and "world" become one phrase.
  3. Finish the line. WriteLine("!") prints ! and moves to the next line.
  4. 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 + "!");
    }
}

How It Works

  1. Same-line prompt. Write leaves the cursor after the colon so typing looks natural.
  2. Sample input. The sample output shows the user typing Ada and pressing Enter.
  3. Null-safe. ?? "" treats end-of-file null as an empty string.
  4. 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);
    }
}

How It Works

  1. Placeholders. {0} is replaced by the next argument.
  2. Trailing space. Spaces in the format keep values readable on one row.
  3. Last call. WriteLine prints the sum and ends the line.
  4. 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.

Next: WriteLine()

Print text (or an empty line) and move to the next line with System.Console.

WriteLine() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful