JetBrains Rider
 
Get JetBrains Rider
Get your hands on the new features ahead of the release by joining the Early Access Program for Rider 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. JetBrains Rider 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.