Skip to main content

Remove Redundant Delegate Creation

Purpose

Removes a delegate object initialization expression under the cursor, and inserts the appropriate method reference instead. In most cases, the explicit delegate creation is redundant and can be removed, which may improve readability.

Availability

Available when the cursor is on a delegate object creation expression.

Usage

  1. Place the caret on a new delegate creation.

    Note

    The blinking cursor shows the caret’s position at which the Refactoring is available.

    textBox1.TextChanged += new EventHandler(ProcessText);
    
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select Remove Redundant Delegate Creation from the menu.

After execution, Refactoring replaces the delegate object initializer with the appropriate method reference.

textBox1.TextChanged += ProcessText;
See Also