In C#, Console.GetCursorPosition returns the cursor’s column and row as a value tuple (int Left, int Top). It is available in .NET 5 and later.
Use it when you need to remember a position before moving the cursor, or to print status text without losing your place. Like other cursor APIs, it is console-window oriented and may throw if the console is redirected or unsupported.
This is a static member of System.Console. You call it with the type name, such as Console.GetCursorPosition(...). Console is the everyday API for reading from standard input and writing to standard output in C# console apps.
Syntax
Deconstruct the tuple into left and top coordinates.
C#
(int left, int top) = Console.GetCursorPosition();
var pos = Console.GetCursorPosition();
Call
What it does
Console.GetCursorPosition()
Returns (Left, Top) for the cursor.
Older code often used Console.CursorLeft and Console.CursorTop separately. GetCursorPosition packages both.
Library declarations
C#
public static (int Left, int Top) GetCursorPosition();
Parameters
Parameter
Description
None
Takes no parameters.
Return Value
Return Value
Description
(Left, Top)
Column (Left) and row (Top), zero-based in the buffer.
C# Examples
Example 1 — Print the Current Cursor Position
Read Left/Top after some output.
C#
using System;
class Program {
static void Main() {
Console.WriteLine("Hello");
(int left, int top) = Console.GetCursorPosition();
Console.WriteLine("Left=" + left + " Top=" + top);
}
}
Output
Hello
Left=0 Top=1
How It Works
After Hello. WriteLine moves the cursor to the next line.
Typical Left 0. New line starts at column 0.
Top advanced. Row increases after the first line (exact value can vary with buffer start).
Tuple deconstruct. Clean syntax for both coordinates.
Example 2 — Remember Position, Write, Then Return
Save coordinates, print elsewhere, then SetCursorPosition back.
C#
using System;
class Program {
static void Main() {
Console.Write("Name: ");
var mark = Console.GetCursorPosition();
Console.WriteLine();
Console.WriteLine("(status line)");
Console.SetCursorPosition(mark.Left, mark.Top);
Console.Write("Ada");
Console.WriteLine();
}
}
Output
Name: Ada
(status line)
How It Works
Mark after prompt. Save where the name should appear.
Temporary status. Print a status on the next lines.
Restore. SetCursorPosition returns to the saved spot.
Sample Ada. Name is written at the original prompt position.
Example 3 — Read Position for an In-Place Counter
Combine GetCursorPosition with SetCursorPosition for a tiny counter.
C#
using System;
class Program {
static void Main() {
Console.Write("Count: ");
var p = Console.GetCursorPosition();
for (int i = 1; i <= 3; i++) {
Console.SetCursorPosition(p.Left, p.Top);
Console.Write(i);
}
Console.WriteLine();
Console.WriteLine("Done");
}
}
Output
Count: 3
Done
How It Works
Anchor. Store the cell after the label.
Overwrite. Each loop writes the new digit in the same place.
Final 3. sample output shows the last value left on screen.