zoukankan      html  css  js  c++  java
  • event 自定义事件

    自定义事件

     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  委托,自己也可以定义一个;

     EventArgs

  • 相关阅读:
    es6 Set 和Map 数据结构
    es6 Symbol
    es6 对象的扩展
    es6 class
    es6 数组扩展方法
    Docker入门01——Image
    GORM 中文文档
    将以前的文章开始慢慢转到这里发表
    环境变量
    在 Linux 中安装 VMware Tools
  • 原文地址:https://www.cnblogs.com/zlp520/p/3837326.html
Copyright © 2011-2022 走看看