Due to the new access to C #, I have also read some of the C # DelegationArticleBut I have never understood it thoroughly. Now I will write down my rough understanding and hope you can give me some advice.
When the parent class wants to call the subclass method, you can consider using delegation: because the parent class cannot call the methods in the subclass, you can call the subclass method by defining the delegate. The procedure is as follows:
1) define a delegate; Public Delegate void openfileeventhandler (Object sender, openfileeventargs E );
2) define an event in the parent class; public event openfileeventhandler openfile;
3) register the event where the subclass instantiates the parent class; openfile + = new openfileeventhandler (openfile); the signature of the openfile () method must be consistent with that of the delegate.
4) call this event where the parent class needs to call the subclass method; If (openfile! = NULL) openfile (sender, e );
In this way, when the parent class runs to openfile (sender, e);, the openfile (); Method in the subclass is called.
I hope you can give us some guidance.