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);
}
}
}
浙公网安备 33010602011771号