Skip to main content

Remove Unused Parameter

  • 2 minutes to read

Purpose

Removes a method parameter if it is never referenced in the method body code.

Note

Remove Unused Parameter is a cascading Refactoring. That means that the Refactoring affects all method calls and method declarations in interfaces, base and descendant classes.

Availability

Available in the following cases:

  • When the cursor is on a method parameter that is never used.
  • When the cursor is on a method name. This method has one or more parameters that are never used.

How to Use

  1. Place the caret on an unused method parameter (for example, in the “param1”).

    private string TestMethod(string param1, int param2)
    {
        return String.Format("the param2 value is {0}", param2);
    }
    
    private void MyMethod()
    {
        string str = TestMethod("My string", 10);
    }
    
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

    OrganizeMembersPage

  3. Select Remove Unused Parameter: <parameter name> from the menu.

After execution, the Refactoring removes the unused parameter from the method signature.

private string TestMethod(int param2)
{
    return String.Format("the param2 value is {0}", param2);
}
private void MyMethod()
{
    string str = TestMethod(10);
}
See Also