Detailed EventHandler in C #

Source: Internet
Author: User
This article introduces the EventHandler in C # through case examples, and the friends you need refer to it.

Needless to say, the detailed details are as follows:

Here defines a water tank class public class water tank {  //This is the water tank's discharge operation public  Void Discharge () {}  //This is the property of the water tank public  double volume;  This is the water tank empty event public event  EventHandler tank empty; This defines a water refill class public class water refill {public  void plus water (Object sender, EventArgs e)  {    //Add water to the water tank that needs to be added  }} public Class user{public  User ()  {    //instantiate tank type    water tank 1 = new water tank ();    Example of water-adding device    1 = new water-adding device ();    Water Refill register Tank empty event    water tank 1. Water tank Empty + = new EventHandler (water refill 1. Add water);  }  Private water-adding water device 1;  Private tank water tank 1;}

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

The most classic explanation for C # delegates:

Example:

This. Activated + = new EventHandler (form1_activated);

This is the principle of a delegate.

This. Activated= you have finished your meal;  Form1_activated= shout Me a voice

The meaning of this sentence is to put these two things together, meaning that you eat the meal after the call me. I entrust you to finish dinner, shout me. So I don't have to take a moment to see if you have finished eating, have entrusted you.

"Recommended"

1. Special recommendation : "PHP Programmer Toolkit" V0.1 version download

2. asp free Video Tutorial

3. Eon the ASP Basic video tutorial

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.