This refactoring allows you to replace all occurrences of a variable in the code with its initializer. Note that the refactoring should be only applied if the variable value stays unchanged after initialization.
In the example below, we use this refactoring to inline the
|Before refactoring||After refactoring|
To inline a variable
- Place the caret at the declaration or a usage of a variable in the editor.
Do one of the following:
- On the main menu, choose
- Right-click and choose Refactor | Inline Variable on the context menu.
- Press Ctrl+Shift+R and then choose Inline Variable
- Press Ctrl+Alt+N and then choose Inline Variable
- If no conflicts are found, ReSharper performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.
This feature is supported in the following languages/technologies:
The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.