0

Possible Duplicate:
C# hide and unhide comments

Is it possible to turn off and on all the // comments at once on Visual Express C#? I comment my code a lot and being able to turn off all of them at once would really help my workflow.

Community
  • 1
  • 1
Arthur Mamou-Mani
  • 2,303
  • 10
  • 43
  • 69

2 Answers2

6

Select the lines then:

Ctrl + K + U

And the opposite:

Ctrl + K + C

You can find the shortcuts also through the menus - Edit -> Advanced -> ... The shortcuts are listed next to the commands.

And of course, these are also on the Text Editor toolbar:

comment buttons on toolbar

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • How does that work on *all* comments? – harriyott Oct 15 '12 at 10:26
  • @harriyott - As I posted at the very start: `Select the lines`. I suspect that the OP doesn't need to comment/uncomment all lines in a solution, project or even a single file. – Oded Oct 15 '12 at 10:37
  • Reading the question, I thought that was exactly what he was asking. He used the word "all" twice. – harriyott Oct 15 '12 at 10:42
  • Hi @harriyott and oded, I did want to hide all the comments at once but your replies were very helpful. One thing though, I got a white rectangle with rounded corners in my breakpoint column, what is that? – Arthur Mamou-Mani Oct 15 '12 at 10:53
  • 1
    @ArthurMamou-Mani - Sounds like a different question ;) Why not post that with an image of what you mean? – Oded Oct 15 '12 at 10:57
  • Thanks @Oded, I got it when typing ctrl+K+U, probably in a wrong way. I will look into it more :) – Arthur Mamou-Mani Oct 15 '12 at 11:01
1

A simpler way might be to use compiler directives instead of comments, e.g.

#ifdef commentedCode
Console.WriteLine("This is a comment");
#endif

Then, in your project settings, on the Build property page, add commentedCode to the Conditional compilation symbols to include the code, and remove it to ignore the code. Not exactly what you asked, but probably quicker than editing multiple files with comments.

harriyott
  • 10,505
  • 10
  • 64
  • 103
  • 1
    Actually, that is not simpler in most use cases. – H H Oct 15 '12 at 10:18
  • 1
    Indeed, not in most cases. But I don't often see coders comment out several blocks of code - I was addressing the *all* part of the question, which the `Ctrl + K + C` answer doesn't address. – harriyott Oct 15 '12 at 10:25