c# clear console read chache

C#
while(Console.KeyAvailable) 
{
    Console.ReadKey(true);
}
Source

Also in C#: