Comment on "delegation" and "events"

Source: Internet
Author: User
During the past few days of study delegation, I suddenly came up with an interesting idea and wrote it out to share with you:

One day, I was hungry. Although I had cabbage and pork, I could have made a delicious cabbage stew with pork, but I didn't make cabbage and pork into Cabbage stew with pork. At this time, I thought of "delegation ":

First, I declare a delegate. to let others know, I declare it as public:

Public   Delegate Cookhandler (cabbage M, pork N );

In this way, no matter who he is, as long as he can turn cabbage and pork into a method for braised pork with cabbage, his method can be used for me. It happened that one of my friends had this method, so his method became an example of my "delegate:

Cookhandler C = New Cookhandler (frienda. Cook );

Then, after entering cabbage and pork, I got the desired Cabbage stew:

Pork stewed cabbage TMP;
TMP = C (cabbage, pork );

It's amazing.

But later, I found that every time I had to delegate, I was very tired and there was no better way. As a metaphor, as long as I was hungry, there was a guy who asked me to get cabbage and stew with pork. Think of this, don't say, there is actually -- that is: the event.

Public   Event Cookhandler hungryevent;

I am familiar with frienda, so I will leave it to him:

This . Hungryevent + = New Cookhandler (frienda. Cook );
Pork stewed cabbage TMP;
TMP= Hungryevent(Cabbage, pork );

It turned out that there was such a good thing, as long as I shouted "I'm hungry", I could always get delicious cabbage and pork stew. (How nice it is in reality)

However, soon after, one day, maybe my friends are no longer happy to serve me unconditionally, maybe for some reason. In a word, it actually appears:

This . Hungryevent -= New Cookhandler (frienda. Cook );

As a result, when I shouted "I'm hungry" as usual, not only did I not get cabbage or pork stew, but I was also hungry and almost crashed the system.

Since then, I have become smart:

If (Hungryevent ! = Null )
{
Braised Pork with Chinese cabbage TMP;
TMP=Hungryevent (cabbage, pork );
}

Every time I call "I'm hungry", I always look at whether someone is willing to use his method for my delegated instance. How is it safe?

This article is just a joke. If you have any improper information, please forgive me.

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.