This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Visual Studio
VS 2003+

Visual Studio Comment Selection

Often when writing and debugging programs you will want to comment out a selection of code temporarily. This can be achieved manually by adding comment markers. Visual Studio also provides commands to quickly comment and uncomment selections.

Comment and Uncomment Selection

The comment and uncomment selection commands are available in Visual Studio version 2003 and later. They provide a handy way to comment out large blocks of code at a time and later remove the comments. The comment selection command inserts a single line comment marker (//) at the beginning of each line of code that is currently selected in the code editor window. The uncomment selection command again works against the currently selected section of code, this time removing the comment symbols and returns the code to its previous formatting.


To comment out a block of code, first select the lines that you wish to be deactivated. You can then execute the command by opening the Edit menu, selecting the "Advanced" sub-menu and clicking "Comment Selection". Alternatively you can use the comment selection toolbar button or press Ctrl-K, C.

NB: In Visual Studio 2008, this shortcut key combination was changed to Ctrl-E, C.


When you need to reintroduce the code that has previously been commented out, you can use the uncomment code command. This is available from the same menu, the toolbar or by pressing Ctrl-K, U. When used, the comment symbols against the currently selected code lines are removed.

NB: In Visual Studio 2008, use Ctrl-E, U.

6 July 2008