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:
and in C#2.0, you can achieve the same thing using the following 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);
}
}
}
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);
}
}
}
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);
}
}
}
![](http://c.spaces.msn.com/CollectionWebService/c.gif?space=shevaspace&page=RSS%3a+Counting+Number+Down+In+Console+Application&referrer=)
![](c.msn.com/c.gif?NC=31263&NA=1149&PI=88469&RF=&DI=3919&PS=85545&TP=spaces.msn.com>1=shevaspace%3b2052)