您的位置:首页 > 移动开发

Counting Number Down In Console Application

2006-01-14 22:35 267 查看
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);
}
}
}



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: