The Introduce Field refactoring allows you to create a new field based on a selected expression, initialize it with the expression, and replace occurrences of the expression in the code with references to the newly introduced field.
- Select an expression in the editor.
-
Do one of the following:
- On the main menu, choose ReSharper| Refactor | Introduce Field.
- Choose Refactor | Introduce Field on the context menu.
- Press Ctrl+Shift+R, then click Introduce Field.
- Press Ctrl+Alt+D.
-
If more than one occurrence of the selected expression is found,
ReSharper displays the drop-down menu.
Choose whether to replace all occurrences or only the selected one.

-
The Introduce Field dialog box opens.
Type the name of a new field in the Name text box or leave the default one.

-
Select an option in the
Introduce field and initialize in
section:
- Current member: initializes the field in the current member (this option is only available if you chose to replace a single occurrence or occurrences within the current member).
- Field initializer: initializes the field right where it is declared.
- Constructor(s): initializes the field in the constructor or constructors of the containing class; if necessary, creates a parameterless constructor and initializes the field from within it.
- Introduce constant: creates a constant instead of a field.
- In the Visibility drop-down list, select the visibility of the new field.
- Select the Make static check box to create a static field.
- Select the Make field read-only check box to create a read-only field.
- Click Next. The new field is created and initialized according to specified settings. One or more occurrences of the selected expression are replaced with usages of the field.
