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

Extract Method refactoring

Last modified: 23 September 2024

This refactoring allows you to create a new method or a local function based on the selected code fragment. ReSharper analyzes the selected statements and detects variables that can be converted into method parameters or represent its return value.

Consider the following example. The method PrintReversed() actually does two things: it reverses the string and prints it. We can select the reversing logic, which is all statements except Console.WriteLine(reversed);, and use this refactoring to move that logic to a new PrintReversed() method.

This feature is supported in the following languages and technologies:

The instructions and examples given here address the use of the feature in C#. For more information about other languages, refer to corresponding topics in the Languages and frameworks section.