我经常发现我需要删除嵌套语句,比如 if 条件变得无关紧要:
来自
if (processFile != null && processFile.Exists)
{
Process[] processesByName = GetProcesses(processFile.NameWithoutExt);
if (processesByName.Length > 0)
{
return processesByName.ToList();
}
}
return null;
至
Process[] processesByName = GetProcesses(processFile.NameWithoutExt);
if (processesByName.Length > 0)
{
return processesByName.ToList();
}
return null;
麻烦的是必须手动找到两边的花括号并删除它们,同时保留嵌套代码
- 尤其是较大的 body ,不像这里的例子
- 有什么方法可以使用 Resharper 快速删除?
- 还是直接在 Visual Studio 中?
最佳答案
Shift+delete
剪切IF
行
Alt+Enter
在括号上删除多余的大括号。
关于c# - 在 Visual Studio 或 Resharper 中快速删除周围语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26160829/