Extract local function refactoring
Applies to: Visual Studio
Visual Studio for Mac
Visual Studio Code
This refactoring applies to:
- C#
What: Lets you turn a fragment of code from an existing method into a local function.
When: You have a fragment of existing code in some method that needs to be called from a local function.
Why: You could copy/paste that code, but that would lead to duplication. A better solution is to refactor that fragment into its own local function.
How-to
Highlight the code to be extracted.
Press Ctrl+. to trigger the Quick Actions and Refactorings menu.
Select Extract local function.
See also
Feedback
Submit and view feedback for