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);
Call
What 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
Parameter
Description
width
Buffer width in columns.
height
Buffer height in rows.
Return Value
Return Value
Description
void
Buffer 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);
}
}
}
Output
BufferWidth=120
BufferHeight=500
How It Works
Safe minimums. Width/height stay at least as large as the window.
Try/catch. Unsupported hosts print a friendly fallback.
Sample success. sample output shows a typical successful resize.
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);
}
}
Output
Buffer: 120x9001
Window: 120x30
How It Works
Buffer vs window. Buffer can be taller than the visible window.
Read properties. Useful before calling SetBufferSize.
Sample numbers. Exact values depend on your terminal.
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");
}
}
}
Output
Set OK -> 120x230
How It Works
Match window width. Avoid shrinking below the visible width.
Extra rows. WindowHeight + 200 adds scroll room.
Catch failures. Redirected runs print the fallback line.
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.