ReSharper
 
Get ReSharper
You are viewing the documentation for an earlier version of ReSharper.

Introduce Variable refactoring

Last modified: 21 July 2022

ReSharper | Refactor | Introduce Variable…

Ctrl+R V (ReSharper_IntroVariable)

This refactoring allows you to create a new local variable or constant based on a selected expression, initialize it with the expression, and finally replace all occurrences of the expression in the method with references to the newly introduced variable.

In the example below, we use this refactoring to replace two occurrences of the same string with a variable:

This feature is supported in the following languages and 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.