You can use carriage return ( \r or U + 000D) to return the cursor to the beginning of the current line, and then overwrite what is there. Sort of
// A bunch of spaces to clear the previous output Console.Write("\r "); Console.WriteLine("\rI just waited 5 seconds"); Console.Write("Please input something: ");
However, if the user has already started typing, this will no longer work (since you cannot overwrite everything they typed, and they will lose what they typed on the screen, although it is still there in memory.
To fix this problem correctly, you really need to change the console character buffer. You should move everything above the current line one line, and then insert your message. You can use Console.MoveBufferArea to move the area up. Then you need to save the current cursor position, move the cursor to the beginning of the line above, write a message and reset the cursor position to the saved one.
And then you should hope that the user will not write while you write your message, because this will ruin the situation. I'm not sure that you can solve this problem by using ReadLine , although you cannot temporarily block something while ReadLine is active. To decide correctly, you may have to write your own alternative to ReadLine , which reads individual keystrokes and will block the common object when writing the resulting character, to avoid simultaneously writing two streams to the console.
source share