Widgets Visual Studio C# Statement Collapsing


I dream in code

About the author

Robert Williams is an internet application developer for the Salem Web Network.
E-mail me Send mail
Go Daddy Deal of the Week: 30% off your order at! Offer expires 11/6/12

Recent comments




Code Project Associate Logo


The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Visual Studio C# Statement Collapsing

Many seasoned developers would argue that if your method is so long, and contains so many nested blocks of code in braces that you need to be able to collapse the sections to make better sense of your code, that you should refactor that code! And of course, they are right. This can be done either by moving sections out to new methods, or perhaps inverting your if statements to reduce nesting. However, lets be honest, when you initially write something, it often starts out as a single really long method and in order to refactor it you still need to identify where each block starts and ends. And of course sometimes you have to work with code other developers wrote. Wouldn't it be nice to be able to collapse a loop, or a try catch block just by clicking on a little minus sign? True you could wrap these sections with regions, but to do that you would have to figure out where the section starts and ends to insert the region statements and by doing that you wouldn't really need them anymore. If you are working in C++ in Visual Studio, you can collapse code blocks, but this functionality is not part of the C# options. Fortunately, there is a Visual Studio 2010 extension you can install to add this functionality to C#.

Posted by Williarob on Friday, April 15, 2011 1:51 PM
Permalink | Comments (0) | Post RSSRSS comment feed
blog comments powered by Disqus