The requested page is not available for the requested platform. You are viewing the content for Default platform.

Remove Unused Parameter

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.
Note

The blinking cursor shows the caret's position where Refactoring is available.

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);
}
  1. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.

OrganizeMembersPage

  1. 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