Example: Make an alarm clock. Focus on learning the flexible use of datetime, jump statement

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.