首页 > 其他 > 详细

自定义事件

时间:2014-07-16 19:49:47      阅读:202      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1  public class Program
 2     {
 3        public event EventHandler ehdl=null;
 4         public Program() 
 5         {
 6             ehdl += Program_ehdl;
 7         }
 8 
 9         void Program_ehdl(object sender, EventArgs e)
10         {
11             var test=e as TestEventArgs;
12             Console.WriteLine("姓名:{0},年龄:{1},性别:{2}",test.Name,test.Age,test.Gender);
13         }
14 
15        
16         static void Main(string[] args)
17         {
18             Program p = new Program();
19             p.Fly();
20             
21             Console.ReadKey();
22         }
23 
24         private  void Fly()
25         {
26             TestEventArgs test = new TestEventArgs();
27             test.Name = "张三";
28             test.Age = "15";
29             test.Gender="";
30             ehdl(this, test);
31            
32         }
33       
34     }
35     public class TestEventArgs : EventArgs 
36     {
37         public string Name { get; set; }
38         public string Age { get; set; }
39         public string Gender { get; set; }
40     }
View Code

EventHandler  委托,自己也可以定义一个;

bubuko.com,布布扣

 EventArgs

bubuko.com,布布扣

 

 

自定义事件,布布扣,bubuko.com

自定义事件

原文:http://www.cnblogs.com/zlp520/p/3837326.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!