DateTime a = datetime.now;//Gets the time of the computer now
DateTime NZ = convert.todatetime ("2015-4-14 22:44");//define the time of the alarm
while (true)
{
A = a.addminutes (1); Display time, one minute plus one minute display
Console.WriteLine (A.toshorttimestring ());//output Display alarm time
if (NZ. Toshorttimestring (). Equals (A.toshorttimestring ()))//If the alarm time is now time,
{
Console.WriteLine ("To the point ... \a\a\a\a\a\a\a\a\a\a\a\a ");//time to produce a beep
Console.WriteLine ("Do you want to turn off the alarm? (y,n) ");
string s = Console.ReadLine ();
if (s.toupper () = = "Y")
{
Break If so, turn off the alarm.
}
Else
{
NZ = NZ. AddMinutes (10); If you do not turn off the alarm, define 10 minutes before ringing, AddMinutes plus 10 minutes, fixed format
}
}
Thread.Sleep (50);
Example: Make an alarm clock. Focus on learning the flexible use of datetime, jump statement