Home » c# » How to collapse If, Else, For, Foreach, etc clauses? [duplicate]

How to collapse If, Else, For, Foreach, etc clauses? [duplicate]

Posted by: admin November 30, 2017 Leave a comment

Questions:

This question already has an answer here:

Answers:

Try this plugin (C# Outline Extension):

Questions:
Answers:

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

Just go to Visual Studio -> Tools -> Options -> Text Editor -> C\C++- > View and set Outline Statement Blocks to true.

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

Questions:
Answers:

I use 2 Extensions:

C# outline 2013

and

Indent Guides

Questions:
Answers:

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 )

Questions:
Answers:

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

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

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