Home >Backend Development >C#.Net Tutorial >Detailed explanation of EventHandler in C#
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; }
---- -------------------------------------------------- ---------------------------------------------
C#'s most classic commission Explanation:
Example:
this.Activated += new EventHandler(Form1_Activated);
This is the principle of delegation.
this.Activated=你吃完饭; Form1_Activated=喊我一声
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
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!