Today, one of my colleagues asked me whether a clear screen function just like the one in dos ( cls ) exists in the framework ! I told him 'Of course. It must be there.' . ahem much to my surprise such a function does not exist in the framework's Console class. I was searching for a method to do this when i bumped onto this Article in C# Corner that precisely does what i exactly want and much more...
The author creates a custom Console window with the help of Win32Native commands and then provides functionality to clear screen, SetColor and SetCursorType ... Why weren't these included in the Console Class ?! It really sounds weird now after being stuck with such a problem that the framework inherently does not provide these utility functions...
Actually thinking about it, it seems simple. If there is a way to flush a stream completely, to make the underlying buffer null using managed code, then voila, that's the solution. Because the Console.Out is a TextWriter that writes the output to the Console stream obtained from the Win32Native functions. The flushing of this buffer should do the trick.. But how to do it ?!! I am clueless ... Anyone tried something like this ?!
Is there any other way to achieve this using completely managed code ?