To introduce a parameter to a method or constructor
In the code editor, select an expression inside a method or constructor:
ReSharper | Refactor | Introduce Parameter, or press Ctrl+Alt+P.
- If the selected expression occurs two or more times in the current method or constructor, ReSharper asks to specify how many
occurrences it should replace:
- If the selected expression occurs only once, the
Introduce Parameterwizard opens immediately:
- If the selected expression occurs two or more times in the current method or constructor, ReSharper asks to specify how many occurrences it should replace:
- Specify the following options:
- In the
Parameter nametext box, choose a suggested name for the new parameter, or enter a custom name.
If the selected expression requires passing the parameter as a lambda expression, select members to en-lambda in the
Select local variables to en-lambdasection.
- In the
Next. If ReSharper discovers no conflicts, the refactoring is applied immediately. The following figure shows how ReSharper generates a delegate parameter:
This is how a method call transforms to pass a lambda expression: