ReSharper Web Help

The Inline Field refactoring replaces a field with its value and removes the declaration of the field. This refactoring works only for fields that have a single write usage.

To inline a field
  1. Place the caret at a field that has exactly one write usage (why it is so?).
  2. Do one of the following:
    • On the main menu, choose ReSharper| Refactor | Inline.
    • Choose Refactor | Inline on the context menu.
    • Press Ctrl+Shift+R, then click Inline Field.
    • Press Ctrl+Alt+N.
  3. If the selected field has more than one write usage, ReSharper reports a conflict. Otherwise, ReSharper inlines the field immediately.

     Note

    If there are several usages of the field within a method, ReSharper creates a local variable and replaces all them with the variable.

Consider the example below:

After applying the refactoring, the read usage of the ourKey field is replaced with initializing expression.

See Also

Procedures