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.