C# Console SetBufferSize() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Console

Definition

In C#, Console.SetBufferSize changes how wide and tall the screen buffer is—the area that can hold characters, including scrollback beyond the visible window.

The buffer must be at least as large as the current window. Invalid sizes or hosts without a real console window can throw. This API is console-window oriented.

This is a static member of System.Console. You call it with the type name, such as Console.SetBufferSize(...). Console is the everyday API for reading from standard input and writing to standard output in C# console apps.

Syntax

Pass width and height in character cells.

C#
Console.SetBufferSize(120, 1000);
CallWhat it does
Console.SetBufferSize(width, height)Sets buffer width and height.

Often paired with SetWindowSize. Buffer size cannot be smaller than the window size.

Library declarations
C#
public static void SetBufferSize(int width, int height);

Parameters

ParameterDescription
widthBuffer width in columns.
heightBuffer height in rows.

Return Value

Return ValueDescription
voidBuffer size changes when supported.

C# Examples

Example 1 — Request a Taller Scrollback Buffer

Increase height so more lines can scroll.

C#
using System;

class Program {
    static void Main() {
        try {
            int w = Math.Max(Console.BufferWidth, Console.WindowWidth);
            int h = Math.Max(Console.BufferHeight, 500);
            Console.SetBufferSize(w, h);
            Console.WriteLine("BufferWidth=" + Console.BufferWidth);
            Console.WriteLine("BufferHeight=" + Console.BufferHeight);
        } catch (Exception ex) {
            Console.WriteLine("Not supported: " + ex.GetType().Name);
        }
    }
}

How It Works

  1. Safe minimums. Width/height stay at least as large as the window.
  2. Try/catch. Unsupported hosts print a friendly fallback.
  3. Sample success. sample output shows a typical successful resize.
  4. Scrollback. Larger height keeps more history.

Example 2 — Print Buffer and Window Sizes

Show current sizes before changing anything.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine("Buffer: " + Console.BufferWidth + "x" + Console.BufferHeight);
        Console.WriteLine("Window: " + Console.WindowWidth + "x" + Console.WindowHeight);
    }
}

How It Works

  1. Buffer vs window. Buffer can be taller than the visible window.
  2. Read properties. Useful before calling SetBufferSize.
  3. Sample numbers. Exact values depend on your terminal.
  4. No set yet. This example only reports.

Example 3 — Only Set When Larger Than Window

Compute a valid height, then set.

C#
using System;

class Program {
    static void Main() {
        int width = Console.WindowWidth;
        int height = Math.Max(Console.WindowHeight + 200, Console.BufferHeight);
        try {
            Console.SetBufferSize(width, height);
            Console.WriteLine("Set OK -> " + Console.BufferWidth + "x" + Console.BufferHeight);
        } catch (Exception) {
            Console.WriteLine("SetBufferSize not available here");
        }
    }
}

How It Works

  1. Match window width. Avoid shrinking below the visible width.
  2. Extra rows. WindowHeight + 200 adds scroll room.
  3. Catch failures. Redirected runs print the fallback line.
  4. Confirm. Print BufferWidth/Height after a successful set.

Frequently Asked Questions

The character grid that holds output, including lines you can scroll back to.
No. That is invalid and typically throws.
Many hosts (IDEs, redirected output) do not support resizing.
SetWindowSize and SetWindowPosition also manage the console window.
It changes size; content handling depends on the host. Do not assume a clear.

Next: SetCursorPosition()

Move the console cursor to a column (left) and row (top) with System.Console.

SetCursorPosition() 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.

8 people found this page helpful