回覆列表
  • 1 # 使用者1062846289535

    using System;

    using System.Timers;

    namespace ConsoleApp

    {

    public class Clock

    {

    private Timer timer;

    private int hour;

    private int minute;

    private int second;

    public Clock()

    {

    timer = new Timer(1000);

    timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);

    }

    public void Start()

    {

    timer.Start();

    }

    public void Stop()

    {

    timer.Stop();

    }

    void timer_Elapsed(object sender, ElapsedEventArgs e)

    {

    DateTime time = e.SignalTime;

    hour = time.Hour;

    minute = time.Minute;

    second = time.Second;

    string display = string.Format("{0}:{1}:{2}",

    hour, minute, second);

    Console.Clear();

    Console.WriteLine(display);

    }

    }

    }

    Main函數里寫new Clock().Start();

    即可。

  • 中秋節和大豐收的關聯?
  • DNF七旬大爺網咖打團,申請漩渦卻遭“踢皮球”,為何看到裝備團長都笑了?