ReSharper 2019.2 Help

Inline Variable refactoring

ReSharper | Refactor | Inline | Inline…
Ctrl+Alt+N
ReSharper_InlineVariable

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.

Before refactoring

After refactoring

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); }

To 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+Shift+R and then choose Inline Variable

    • Right-click and choose Refactor | Inline Variable in the context menu.

    • Choose ReSharper | Refactor | Inline | Inline… in the main menu.

  3. 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 and technologies:

Language: C# Language: VB.NET Language: C++ Language: HTML Language: ASP.NET Language: Razor Language: JavaScript Language: TypeScript Language: CSS Language: XML Language: XAML Language: Resx Language: Build Scripts Language: Protobuf Language: JSON
Feature is available Feature is not available Feature is available Feature is not available Feature is not available Feature is not available Feature is available Feature is available Feature is not available Feature is not available Feature is not available Feature is not available Feature is not available Feature is not available Feature is not available

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.

Last modified: 18 November 2019