Search code examples
c#console-applicationline

Clearing a line in the console


How can a line in the console be cleared in C#?

I know how to place the cursor at the beginning of a line:

Console.SetCursorPosition(0, Console.CursorTop);

Solution

  • Simplest method would be to move to the start of the line, as you have done, and then write out a string of spaces the same length as the length of the line.

    Console.Write(new String(' ', Console.BufferWidth));