C# 如何折叠 If、Else、For、Foreach 等子句?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11258628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 17:09:13  来源:igfitidea点击:

How to collapse If, Else, For, Foreach, etc clauses?

c#visual-studiovisual-studio-extensionsclause

提问by Moslem Ben Dhaou

I get stuck sometimes with very long clauses and I am looking for a way that allows me to collapse them, same way as I can collapse classes, methods and namespaces by default.

有时我会被很长的子句卡住,我正在寻找一种允许我折叠它们的方法,就像我可以默认折叠类、方法和命名空间一样。

Is there a Visual Studio extension that does that? neither ReSharper nor JustCode does allow it.

是否有一个 Visual Studio 扩展可以做到这一点?ReSharper 和 JustCode 都不允许。

Thank you!

谢谢!

采纳答案by TWT

Try this plugin (C# Outline Extension):

试试这个插件(C# 大纲扩展):

回答by Jainendra

You can use #regionfor collapsing if, else, for and other similar clauses.
Example:

您可以#region用于折叠 if、else、for 和其他类似子句。
例子:

#region foreach
foreach(/*conditions*/) 
{
    statement 1;
    statement 2;
    ..
    statement n;
}
#endregion

Now for collapse all use the shortcut ctrl+M,ctrl+O.

现在折叠所有使用快捷方式ctrl+ M, ctrl+ O

回答by Hamza_L

select the code you want to collapse and then press ctrl+M,ctrl+H. to disable it, press ctrl+M,ctrl+U, you can also right click on the selection, and there "Plan Mode" ( I'm not sure my VS is french )

选择要折叠的代码,然后按 ctrl+M、ctrl+H。要禁用它,请按 ctrl+M,ctrl+U,您也可以右键单击选择,然后出现“计划模式”(我不确定我的 VS 是法语)

回答by Renzo Ciot

I use 2 Extensions:

我使用 2 个扩展:

C# outline 2013

C# 大纲 2013

and

Indent Guides

缩进指南

回答by surega

Visual studio IDE gives an option to outline the if, for, foreach, while, switch case etc.

Visual Studio IDE 提供了一个选项来概述 if、for、foreach、while、switch case 等。

Just go to Visual Studio -> Tools -> Options -> Text Editor -> C\C++- > Viewand set Outline Statement Blocksto true.

只需转到Visual Studio -> Tools -> Options -> Text Editor -> C\C++- > View并设置Outline Statement Blocks为true。

In Visual Studio 2012+, the path is Visual Studio -> Tools -> Options -> Text Editor -> C\C++- > Formatting.

在 Visual Studio 2012+ 中,路径为Visual Studio -> Tools -> Options -> Text Editor -> C\C++- > Formatting.