provided by: 
Originally published at Internet.comThis article is an excerpt from the book Sams Teach Yourself the C# Language in 21 Days.
The following listing presents a neat little program that is not well designed. It is simple, and there is nothing complex presented in it. It simply prints the time to the console. Forever.
Listing 1. timer.cs - Displaying the time. 1: // Timer01.cs - Displaying Date and Time 2: // Not a great way to do the time. 3: // Press Ctrl+C to end program. 4: //--------------------- 5: using System; 6: 7: class myApp 8: { 9: public static void Main() 10: { 11: while (true) 12: { 13: Console.Write("r{0}", DateTime.Now); 14: } 15: } 16: }
5/26/2003 9:34:19 PM
As you can see, this listing was executed at 9:34 on May the 26th. This listing presents a clock on the command line. This clock seems to update the time every second. Actually it us updating much more often than that; however, you only notice the changes every second when the value being displayed actually changes. This program runs until you break out of it using Ctrl+C.
In line 13, a call to DateTime is made. DateTime is a structure that is available from the System namespace within the base class libraries. This structure has a static method called Now that returns the current time. There are a large number of additional data members and methods within the DateTime structure. You can check out the .NET Framework class library documentation for information on these. There are also a few other aritcles here on CodeGuru.com ...
Read article at Internet.com site