Clear Console Buffer

前端 未结 1 1801
遇见更好的自我
遇见更好的自我 2020-12-15 07:14

I\'m writing a sample console application in VS2008. Now I have a Console.WriteLine() method which displays output on the screen and then there is Console

相关标签:
1条回答
  • 2020-12-15 07:57

    Unfortunately, there is no built-in method in Console class. But you can do this:

    while(Console.KeyAvailable) 
        Console.ReadKey(false); // skips previous input chars
    
    Console.ReadKey(); // reads a char
    

    Use Console.ReadKey(true) if you don't want to print skipped chars.

    Microsoft References

    Console.KeyAvailable

    Console.ReadKey(bool)

    0 讨论(0)
提交回复
热议问题