Rename refactoring

Would a variable by any other name read as clearly?

Tip Screenshot

Rename refactoring

Naming doesn't really have to be that hard. Especially when there's rename refactoring!

As you write code and add more conditional statements, expressions, and other constructs you'll have some clashes with names or naming styles that you want to change. Alternatively, you may need to align the terminology in software to match business jargon, so business rules are expressed in a more straightforward way in code. Once we rename something, we are reminded that variables, expressions, and functions are called from many place in the codebase. If a name is changed, it needs to also be changed everywhere it is called. This could mean thousands of named references to update in large projects. Not fun! Fortunately, both Rider and ReSharper properly update all references to the new name, so we don't have to.

To refactor names in Rider or ReSharper, choose the entity you want to change, such as a variable, class, or method and change it. The IDE recognizes the change and displays a light bulb indicating there's an action you can take. To continue, press ⌘⇧R (macOS) / Ctrl+Shift+R (VS Windows/Linux) to invoke the refactoring dialog. Select Apply Rename Refactoring, and you're done! Rider updated all the required references.


Related Resources

File-scoped namespaces and types
File-scoped namespaces and types
Organize code better and reduce bugs by using file-scoped namespaces and objects
C# Top-level statements
C# Top-level statements
Use top-level statements in C# to reduce boilerplate code.
Global usings
Global usings
Organize `using` statements so they're out of your way.