The Inline Variable refactoring allows users to replace all occurrences of a given variable in the code with its initializer.
- In the editor, place the caret at the name of the variable.
- On the ReSharper menu or context menu, choose Refactor | Inline, or press Ctrl+Alt+N. The variable will be inlined immediately.
Consider the following example:
After we inline the variable
ReSharper modifies the code in the following way:
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.