asp.net4.5 practice~test3-13

 Console program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test3_13
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入你的姓名:");
            string name = Console.ReadLine();
            ProcessTime p = new ProcessTime();
            MyTime t = new MyTime();
            t.Timer += new TimeEventHandler(p.GenerateTime);
            t.OnTimer(name);
        }


    }

    public delegate void TimeEventHandler(string s);

    class MyTime
    {
        public event TimeEventHandler Timer;
        public void OnTimer(string s)
        {
            if (Timer != null)
            {
                Timer(s);
            }
        }
    }

    class ProcessTime
    {
        public void GenerateTime(string s)
        {
            Console.WriteLine("你好{0},现在的时间是{1}",s,DateTime.Now);
        }
    }
}

 

Guess you like

Origin blog.csdn.net/modern358/article/details/113665841