.NET Discussion

.NET Issues, Problems, Code Samples, and Fixes

Visual Studio.NET: How To Comment/Uncomment Large Blocks of Code


Just a quick tip that I find extremely useful: To comment a large block of code (at least for VB.NET, I don’t know if it works in C#, but I assume it does), highlight the area you want to comment out and hold Ctrl and press K and then C. To uncomment, highlight the commented area and hit Ctrl + K + U. The mass uncommenting merely removes the forward-most apostrophe, so if you have actual comments in your commented code that were included in your initial highlighted region, they will remain comments upon uncommenting.

I use this technique a lot for debugging large areas of code.

April 14, 2008 - Posted by | ASP.NET, Tips & Tricks, Visual Studio.NET

9 Comments »

  1. Doesn’t necessarily have to be “large” blocks of code. It works anywhere. Thanks for the tip though 🙂

    Comment by Raza | May 6, 2008 | Reply

  2. True! However, typically for smaller blocks I just hit the apostrophe key. Thanks for the comment 🙂

    Comment by Some.Net(Guy) | May 6, 2008 | Reply

  3. Thanks a lot for your tip. I recently began coding in VB.Net for my seniour project. I have found it much more advanced than the language I know before (C++).

    Finally, I want to know what threading is and how to use it in VB.Net. Please post something about it.

    Have a nice time.

    Comment by Nebrom | May 23, 2008 | Reply

  4. Check out http://www.helpwithdotnet.com/

    Specialized Search Engine to help you with DotNet (.NET) development

    Comment by raj | July 26, 2008 | Reply

  5. Yes, I agree.

    This keystroke is useful on a large block of code. Most of the time, a simple apostrophe will do…:)

    Comment by Stephen | August 3, 2008 | Reply

  6. It worked thanks.

    Comment by thankxx | June 23, 2009 | Reply

  7. For VB.net 2008, under the “Edit” menu, select “Advanced” and then either “Comment Selection” or “Uncomment Selection”.

    Comment by John | June 9, 2011 | Reply

    • This trick works on both C# and VB.NET in VS08 and VS10 (and maybe VS05, but I haven’t tested it)

      Comment by Some.Net(Guy) | June 9, 2011 | Reply

  8. Thanx for tip, really handly for any code demanding commenting

    Comment by $Kay | May 13, 2013 | Reply


Leave a comment