Skip to main content

Remove Redundant Delegate Creation (C#)

Removes a delegate object initialization expression under the cursor, and inserts the appropriate method reference instead.

#Availability

Available from the context menu or via shortcuts:

  • when the cursor is in the right part of a delegate object initialization expression.

#Examples

private void TestMethod()
{
    MyHandler += new EventHandler(MyMethod);
}
private System.EventHandler MyHandler;
private void MyMethod(Object sender, EventArgs e)
{

}

Result:

private void TestMethod()
{
    MyHandler += MyMethod;
}
private System.EventHandler MyHandler;
private void MyMethod(Object sender, EventArgs e)
{

}

#Screenshot

rsRemoveRedundantDelegateCreation