The Inline Variable refactoring allows you to replace all occurrences of a given variable in the code with its initializer.
- Place the caret at the name of a variable in the editor.
Do one of the following:
- On the main menu, choose ReSharper| Refactor | Inline.
- Choose Refactor | Inline on the context menu.
- Press Ctrl+Shift+RCtrl+Shift+R, then click Inline Variable.
- Press Ctrl+Alt+NCtrl+R,I.
- The variable will be inlined immediately.
Consider the example below:
After applying the refactoring, the usage of the r variable is replaced with its initialisation expression.
The Inline Variable refactoring can only be applied to variables if their values keep unchanged after initialization. If a variable violates this condition, an error is reported.
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 the corresponding topics in the ReSharper by Language section.