I recently learned about the concept of delegation and then looked at the combined delegation and events. I found myself ignoring many basic things. This articleArticleNext I will go on to the article "I understand the delegate (delegate)" http://cowbird.cnblogs.com/archive/2006/02/10/328394.html ). For beginners like me to learn.
There is also the concept of combined delegation. Two methods are described in the previous article, as follows:
Use method 1 This. myfunction (New is included in the proxy statement (prepare method 1 ));
Use method 2 This. myfunction (New is included in the proxy statement (prepare the attachment method 2 ));
Add another, use method 3 this. myfunction (New is included in the proxy statement (prepare the supplementary method 1)
+ New proxy statement to be attached (method 2 to prepare for attachment)
-New proxy statement to be attached (method 2 to prepare for attachment ));
Actually, method 3 = method 1 is the concept of delegated combination. Maybe you can't figure out how to use it like me.
After checking the delegate, you will naturally encounter custom events (most custom events use the delegate method ). The difference between them is that they delegate a method, and now they delegate an event.
CodeThe difference is that the original method of use 1 This. myfunction (New is included in the proxy statement (prepare the supplementary method 1 ));
The current method of use is a class. myevent + = new is included in the proxy statement (prepare the event 1 );
In addition, user-defined events are often inserted into some original events, so it is hard to understand the inheritance class and overload method.
Preparation 1
1) Internal statement of the subject
Public Delegate void proxy Declaration for the event (Object sender, eventargs E );
2) methods for declaring proxy in the subject
// Inherit class
Public class myarraylist: arraylist
{
Public event proxy declaration about the event myevent;
// Here, the overload class
Public override int add (object value)
{
Int I = base. Add (value );
Myevent (this, eventargs. Empty );
Return I;
}
}
Preparation 2
1) the method for preparing the attachment for the external Writing of the subject. The parameters stated above are consistent with the returned values.
Private void prepare the attached Event 1 (Object sender, eventargs E)
{
}
You can also declare a few more
Private void prepare the attached event 2 (Object sender, eventargs E)
{
}
Preparation 3
Myarraylist. myevent + = new proxy statement to be added (prepare the event 1 );
At this time, the delegate combination has begun to make sense. In many scenarios, multiple events need to be executed accordingly.
For example, myarraylist. myevent + = new is the proxy Declaration of the object (prepare the object Event 1 + prepare the object event 2 );
Event tutorial reference
Http://msdn.microsoft.com/library/chs/default.asp? Url =/library/CHS/csref/html/vcwlkeventstutorial. asp