How to modify the previous line of console text?

前端 未结 3 749
渐次进展
渐次进展 2020-12-05 09:57

I\'d like to achieve something like this:

Time consuming operation...OK
Another time consuming operation...
And another one, but it completed, so...OK
         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 10:45

    Use a carriage return. This sample prints a single line, overwriting what was there before.

      Console.WriteLine();
      for (int i = 0; i <= 100; i++)
      {
        System.Threading.Thread.Sleep(10);
        Console.Write("\x000DProgress: " + i);
      }
    

    This works as long as all your strings are less than 80 columns (or whatever your terminal buffer is set to).

提交回复
热议问题