The Introduce Parameter refactoring allows you to add a new parameter to a function from a local variable or a constant inside its body. All calls to the function are automatically updated with the appropriate value passed as the new parameter.
To introduce a parameter:
-
In the code editor, select a local variable or a constant inside a function.
-
Do one of the following:
- Select ReSharper | Refactor | Introduce Parameter in the main menu.
- Right-click on the name of the field in the editor and select Refactor | Introduce Parameter in the context menu.
- Press Ctrl + Shift + R and select Introduce Parameter.
- In the dialog that appears, select the necessary options and click Continue.
Example
- In the function below, we would like to pass the day of the week as a parameter. We select the constant that determines the pay day:

- With the constant selected, invoke the Introduce Parameter refactoring. The following dialog is displayed:

- Do the following to apply the refactoring successfully:
- Select the type of the new parameter. ReSharper suggests the type based on the type of the variable/constant.
- Type the new parameter name. ReSharper suggests a name based on the name of the variable/constant.
- Select to Replace all occurrences of the constant if you want to insert the value of the selected variable/constant in all calls to the function. If only occurrence is present in the existing code, the checkbox will be unavailable.
- After you click Continue, the code is updated as shown below:

If no conflicts are found, the changes are applied immediately.
See Also
Refactoring Code