Home > Backend Development > C#.Net Tutorial > Detailed explanation of EventHandler in C#

Detailed explanation of EventHandler in C#

巴扎黑
Release: 2017-05-15 10:31:37
Original
2873 people have browsed it

This article introduces eventhandler in c# through case examples. Friends who need it can refer to it

No more nonsense, the specific details are as follows:

//这里定义了一个水箱类
public class 水箱
{
  //这是水箱的放水操作
  public void 放水() { }
  //这是水箱的属性
  public double 体积;
  //这是水箱空的事件
  public event EventHandler 水箱空;
}
//这里定义了一个加水器类
public class 加水器
{
  public void 加水(Object sender, EventArgs e)
  {
    //对需要加水的水箱进行加水操作
  }
}
 public class User
{
  public User()
  {
    //实例化水箱类
    水箱1 = new 水箱();
    //实例化加水器类
    加水器1 = new 加水器();
    //加水器注册水箱空事件
    水箱1.水箱空 += new EventHandler(加水器1.加水);
  }
  private 加水器 加水器1;
  private 水箱 水箱1;
}
Copy after login

---- -------------------------------------------------- ---------------------------------------------

C#'s most classic commission Explanation:

Example:

this.Activated += new EventHandler(Form1_Activated);
Copy after login

This is the principle of delegation.

this.Activated=你吃完饭;  
Form1_Activated=喊我一声
Copy after login

This sentence means to put these two things together, which means Call me when you finish eating. I entrust you to call me after you finish your meal. This way I won't have to check after a while to see if you've finished eating. I've already entrusted you with it.

【Related Recommendations】

1. Special Recommendation: "php Programmer Toolbox" V0.1 version download

2. ASP Free Video Tutorial

3. Li Yanhui ASP Basic Video Tutorial

The above is the detailed content of Detailed explanation of EventHandler in C#. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
c
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template