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

Remove code redundancies

Last modified: 11 February 2024

On the Code Inspection | Inspection Severity page of ReSharper options Alt+R, O, in the Redundancies in Code categories of different languages, ReSharper lists a lot of code redundancies that have associated code inspections. For most of these redundancies, ReSharper provides quick-fixes. Some code redundancies cannot be fixed automatically, and quick-fixes for them are performed in the interactive mode, requiring the user input. But the majority of the redundancies can be fixed without user interaction, using either fix in scope or code cleanup.

From any code redundancy highlighted by the design-time code inspection, you can invoke the 'Remove redundant code' quick-fix that will remove the current redundancy as well as all redundant code in the file, project or solution:

Remove redundant code quick-fix

Another option to remove code redundancies in a bulk mode is code cleanup. You can either run code cleanup with the Built-in: Full Cleanup profile or create and run a custom profile solely targeted at your specific task as described below.

If you want to remove code redundancies without opening the Code Cleanup dialog to choose a profile, you can bind the created profile to the silent cleanup and run it by pressing Ctrl0E,0F. You can also create a custom cleanup profile that would combine removing code redundancies with other code style tasks.

You can remove code redundancies every time you save changes in a file to make sure that your edits always comply with your code style.

This feature is supported in the following languages and technologies: