使用英语阅读

通过


提取本地函数重构

此重构适用于:

  • C#

功能: 将代码片段从现有方法转换为本地函数。

使用时机: 需要从本地函数调用某些方法中现有的代码片段时。

操作原因: 可以复制/粘贴该代码,但这样会导致重复。 更好的解决方案是将此片段重构为其自己的本地函数。

操作说明

  1. 突出显示要提取的代码。

  2. 按 (Ctrl+.) 触发“快速操作和重构”菜单。

  3. 选择“提取本地函数”。

    Screenshot of the Visual Studio code window with a line highlighted. The Quick Actions and Refactorings menu is open and Extract local function is selected.

另请参阅