Back to Devexpress

Remove Unused Parameter

coderushforroslyn-115567-refactoring-assistance-remove-unused-parameter.md

latest1.9 KB
Original Source

Remove Unused Parameter

  • Aug 19, 2021
  • 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”).

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

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

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

csharp
private string TestMethod(int param2)
{
    return String.Format("the param2 value is {0}", param2);
}
private void MyMethod()
{
    string str = TestMethod(10);
}
vb
Private Function TestMethod(ByVal param2 As Integer) As String
    Return String.Format("the param2 value is {0}", param2)
End Function

Private Sub MyMethod()
    Dim str As String = TestMethod(10)
End Sub

See Also

Promote to Parameter

Remove Unused Member

Remove Redundant Constructor

Remove Redundant Assignment

Add/Remove Block Delimiters