When I first learnt assembly language programming in college, I planned to write a programme which can count down a specified number , and I can still remember how tricky that was when you had to write such a programme in assembly language, but now in C#, you can achieve this just with some trivial code:
using System;

class Program
{
    
static void Main(string[] args)
    {
        
for (Int32 i = 0; i < 50; i++)
        {
            Console.Write(
"Counting {0}\r", i);
            System.Threading.Thread.Sleep(
200);
        }
    }
}

and in C#2.0, you can achieve the same thing using the following code:
using System;

class Program
{
    Int32 currentPos 
= Console.CursorTop;
    Console.CursorVisible 
= false// Hide the cursor, so you don't see the flickering console output
    static void Main(string[] args)
    {
        
for (Int32 i = 0; i < 50; i++)
        {
            Console.WriteLine(
"Counting {0}", i);
            Console.CursorTop 
= currentPos;
            System.Threading.Thread.Sleep(
200);
        }
    }
}



Counting Number Down In Console ApplicationCounting Number Down In Console Application

相关文章:

  • 2021-09-28
  • 2022-02-09
  • 2021-09-11
  • 2021-11-20
  • 2021-12-16
  • 2022-12-23
  • 2021-10-02
  • 2021-07-10
猜你喜欢
  • 2021-06-03
  • 2021-12-19
  • 2022-12-23
  • 2021-07-18
  • 2021-08-06
  • 2021-09-25
  • 2022-12-23
相关资源
相似解决方案