C# EventHandler 委托

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

namespace EventHandlerTest
{
    class Program
    {
        //委托
        public delegate void EventHandler(string a);
        //事件
        public static event EventHandler SetCode;
        static void Main(string[] args)
        {
            //注册
            Program.SetCode += GetCode;
            //触发
            SetCode("触发");
        }

        public static void GetCode(string s)
        {
            Console.WriteLine(s);
        }
    }
}

MSDN EventHandler 委托

你可能感兴趣的:(C#,delegate)