event

来源:互联网 发布:淘宝店铺视频制作 编辑:程序博客网 时间:2024/05/23 00:03
public class SampleEventArgs    {        public SampleEventArgs(string s) { Text = s; }        public String Text {get; private set;} // readonly    }    public class Publisher    {        // Declare the delegate (if using non-generic pattern).        public delegate void SampleEventHandler(object sender, SampleEventArgs e);        // Declare the event.        public event SampleEventHandler SampleEvent;        // Wrap the event in a protected virtual method        // to enable derived classes to raise the event.        protected virtual void RaiseSampleEvent()        {            // Raise the event by using the () operator.            if (SampleEvent != null)                SampleEvent(this, new SampleEventArgs("Hello"));        }

0 0
原创粉丝点击