Search code examples
c#console

Console.Clear() is not clearing the console


(IDE: Jetbrains Rider)

I am trying to make a Rock Paper Scissors game. After the game is over, the program asks if the player wants to play again. If the player plays again, it clears the console but that doesn't work.

Then i tested writing a while loop that Clears the console, then writes a number.

I made a extra project where i wrote this in.

namespace Test
{
    
    public class Program 
    {
    
        public static void Main(string[] args)
        {
            double num = 1;
            while (true)
            {
               Console.Clear();
               Thread.Sleep(100);
               Console.WriteLine();
               num += 1;
            }
        }

    }

}

The loop is the only thing running.

And the output is:


60

71
74

85

93

124
127

162
165

Does anyone know why?

I thought the problem was .Net 5.0, because i changed to .Net Framework 4.8, and it worked.

Now i restarted rider, and the problem is coming again.


Solution

  • I use VS 2019 and .Net 5.0, There is no problem with Console.Clear() Maybe there is an IDE issue. Jetbrains Rider is "buggy" sometimes.

     class Program
    {
        static void Main(string[] args)
        {
            double num = 1;
            while (true)
            {
                Console.Clear();
                Console.WriteLine(num);
                Thread.Sleep(2000);
                num += 1;
            }
        }
    }