This is a pretty good solution to organize the codes. But as we keep adding them, it soon turns out to be more messy than ever before. Sometimes we might even prefer to temporarily collapse a particular block. This is not a problem for classes or methods. But what if we want the same for any arbitrary statements or piece of code? Wouldn’t that be great?
No worries. VS already has a solution for us. Its always been there in front of us and yet we failed to discover.
stop it … and show me how?
Ok. First of all select the the code you want to collapse then right click the editor and click Outlining > Hide Selection.
Did you notice something weird? I actually selected only the condition inside the if statement and hid the selection. It would then look as below.
Isn’t that cool?
Now try closing that file and reopen. VS is smart enough to remember the old collapsible selection.
So, the shortcut of the day would be Ctrl + M, Ctrl + H to hide the current selection.
(This is a part of my series Visual Studio Tips and Tricks – X)