I have numerous occurrences of the following in my code:
this.webBrowserCtrl.DocumentCompleted -= new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.LoginScreenLoaded);
this.webBrowserCtrl.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.AttemptLoginAnalysis);
I wish to remove this and use a simple method that takes 2 inputs – however I don’t know what the types would be.
private void DefineNewDocumentCompletedHandler(TYPEA inputA, TYPEB inputB)
{
this.webBrowserCtrl.DocumentCompleted -= new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(inputA);
this.webBrowserCtrl.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(inputB);
}
Does anyone know what TYPEA and TYPEB should be? Or another way to accomplish my goal?
Use the delegate type on the input parameters, like this:
Example of use:
The syntax
new <delegate type>(<name of method>)is a C# 1.x construct that is now obsolete. From C# 2.0 onwards, you can just specify the name of the method without parentheses, and the compiler will automatically wrap it in a delegate instance for you.