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);
}
}
}
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);
}
}
}
相关文章推荐
- Show Console Window in Windows Application
- Using Spring.net in console application
- How to load "CodedUItestmethod" in another "consoleapplication".
- Coloring the Console Application (AddingText and Background color in C#)
- Counting-the-number-of-set-bits-in-an-integer
- Fix Visual Studio 2013 Razor CSHTML Intellisense in Class Library or Console Application
- Using Spring.net in console application
- How to invoke console application in Perl ?(Reship)
- Step By Step - Using Silverlight to Access a WCF Service Hosted In a Console Application
- 控制台打印表格 (print tables in console application)
- Using a Console in Winform Application
- How to debug c++ console application with argument in visual studio 2012
- Counting number of line in a file
- GUI application run in console mode
- C# Clipboard in Console Application
- First WCF App (Host in Console Application)
- How to write a console application running in background (hidden window)?
- C# Clipboard in Console Application
- 70 lines to Implement 'Hosting a WCF Service in a Console Application'
- [转载]Step By Step - Using Silverlight to Access a WCF Service Hosted In a Console Application