EventHandler in C,

Source: Internet
Author: User

EventHandler in C,

// A water tank class is defined here
Public class water tank
{
// This is the water tank flushing operation
Public void drain (){}
// This is the property of the water tank.
Public double volume;
// This is an empty water tank event.
Public event EventHandler tank is empty;
}

// A water heater class is defined here
Public class Water Heater
{
Public void (Object sender, EventArgs e)
{
// Add water to the water tank to be added
}
}
Public class User
{
Public User ()
{
// Instantiate the Water Tank Class
Tank 1 = new tank ();
// Instantiate the water heater class
Sprinkler 1 = new sprinkler ();

// Register the empty water tank event with the water heater
Tank 1. Empty tank + = new EventHandler (water dispenser 1. Add water );
}

Private Water Heater 1;
Private Water Tank 1;
}

The most classic interpretation of delegate C:

Example: this. Activated + = new EventHandler (Form1_Activated );

This is the principle of delegation.
This. Activated = after dinner;
Form1_Activated = give me a shout

This sentence means to put these two things together, that is, to call me after dinner. I entrusted you with a meal and shouted at me. In this way, I don't need to wait a while to see if you have finished eating and have already commissioned you.

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.