Clearing a line in the console

后端 未结 4 1525
青春惊慌失措
青春惊慌失措 2021-02-10 10:50

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         


        
4条回答
  •  执笔经年
    2021-02-10 11:34

    (Combining at.toulan and Andrew's answers here.)

    Simplest is, to overwrite over the last line:

    Console.SetCursorPosition(0, Console.CursorTop - 1)
    Console.WriteLine("new line of text");
    

    If "new line of text" is shorter than the text that was there before, write spaces before writing your text, like Andrew says.

提交回复
热议问题