ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Private field can be converted into local variable

Last modified: 08 April 2024

ReSharper helps you respect the principle of locality: if a field is only assigned and used in a local scope, ReSharper suggests converting the field to a local variable.

First, this transformation will normally reduce memory usage (however, this effect may be minimized by JIT optimization). Second, it will improve readability of your code.

Here is an example of a quick-fix suggested by this inspection: