Remove Assignments to Parameters
- 2 minutes to read
In This Article
Converts an assignment to a parameter, into a new local variable and fixes all references to point to the new variable.
#Purpose
Changing parameter values within a method makes the code harder to read.. This refactoring declares a new local variable above the original assignment, then initializes it with the parameters value, and converts all subsequent references to use the new local variable.
#Availability
Available from the context menu or via shortcuts:
- when the edit cursor, or caret is on a parameter declaration or reference provided that the parameter has an assignment within the method’s body.
#Tips
- Remove Assignments to Parameters is a special case of Split Temporary Variable as both deal with reducing the complexity of code containing variables that have multiple behaviors in a single block of code.
#Example
private int TestMethod(int a, int b)
{│b = a + b;
return b;
}
Private Function TestMethod(ByVal a As Integer, ByVal b As Integer) As Integer│b = a + b
Return b
End Function
Result:
private int TestMethod(int a, int b)
{
int bResult = a + b;
return bResult;
}
Private Function TestMethod(ByVal a As Integer, ByVal b As Integer) As Integer
Dim bResult As Integer = a + b
Return bResult
End Function
#Animation
See Also