JetBrains Rider 2021.1 Help

Inline Variable refactoring

Refactor | Inline | Inline...
Ctrl+Alt+N

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 reversed variable.

static string ReversedString(string input) { var chars = input.ToCharArray(); Array.Reverse(chars); var reversed = new string(chars); return reversed; }
static string ReversedString(string input) { var chars = input.ToCharArray(); Array.Reverse(chars); return new string(chars); }

Inline a variable

  1. Place the caret at the declaration or a usage of a variable in the editor.

  2. Do one of the following:

    • Press Ctrl+Alt+N and then choose Inline Variable

    • Press Ctrl+Alt+Shift+T and then choose Inline Variable

    • Choose Refactor | Inline Variable in the main menu.

  3. If no conflicts are found, JetBrains Rider performs the refactoring immediately. Otherwise, it prompts you to resolve conflicts.

Last modified: 08 March 2021