locked
Block comment in C# keeps adding * RRS feed

  • Question

  • When I use a block comment /* */ in C# every line is preceeded by an * which is fine when the comment is really a comment.  However sometimes I need to comment out an entire block of code or a section and everytime I hit the enter key an * shows up.  This is a problem because I have to remove all of them to re-activate the code and sometimes I miss one or two then the code doesn't compile and I have to edit the code again.  It is distracting to my thought process, I lose my place and have to spend time going back over what I just did.

    I have looked at customizing the editor and cannot find anything pertaining to comments for any language. Basically it is non-productive feature, if I had not wanted block comments I would be writing in VB.  I spend more time reformatting my code than I do writing it and it is annoying as h$!!, can someone tell me why Microsoft is trying to make C# work like the worst of VB?

     

     

    • Moved by Brittany Behrens Thursday, December 9, 2010 12:43 AM (From:Visual Studio Editor)
    Sunday, November 21, 2010 3:37 AM

Answers

  • HI Pamela,

    The editor works this way to make it easy to write comments. If your need is to comment out code (one or more lines), you simply comment them out using //. There is a very handy keyboard shortcut CTRL-K, CTRL-C.

    This way you can easily remove parts of your code and later decide what to do with them. 

    Kind regards,
    Tom de Koning


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Proposed as answer by Tom de Koning Sunday, November 21, 2010 5:17 PM
    • Marked as answer by Victor_Chen Monday, November 29, 2010 2:17 AM
    Sunday, November 21, 2010 5:17 PM

All replies

  • HI Pamela,

    The editor works this way to make it easy to write comments. If your need is to comment out code (one or more lines), you simply comment them out using //. There is a very handy keyboard shortcut CTRL-K, CTRL-C.

    This way you can easily remove parts of your code and later decide what to do with them. 

    Kind regards,
    Tom de Koning


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Proposed as answer by Tom de Koning Sunday, November 21, 2010 5:17 PM
    • Marked as answer by Victor_Chen Monday, November 29, 2010 2:17 AM
    Sunday, November 21, 2010 5:17 PM
  • hi Pamela,

    slightly OT:

    there is normally no reason to comment out an entire block of code. If you can do so, you have in most cases a block of code - an aspect or concern - which is worth being extract to its own method:

    http://sourcemaking.com/refactoring/long-method
    http://en.wikipedia.org/wiki/Separation_of_concerns

    Also use a version control system like SVN, hg or TFS. Then you can simply delete the code for test purposes. And revert the changes afterwards.


    Microsoft MVP Office Access
    https://mvp.support.microsoft.com/profile/Stefan.Hoffmann
    Thursday, December 9, 2010 9:44 AM
  • Am I the only one who recognizes this keystroke combination?  CTRL-K, CTRL-C used to be block copy in Wordstar, back in the 80s.  BTW, to uncomment, use CTRL-K, CTRL-U.

    --Al--

    • Proposed as answer by ToolMan121 Friday, November 30, 2012 9:05 PM
    • Unproposed as answer by ToolMan121 Friday, November 30, 2012 9:05 PM
    • Proposed as answer by ToolMan121 Friday, November 30, 2012 9:06 PM
    • Unproposed as answer by ToolMan121 Friday, November 30, 2012 9:06 PM
    Friday, August 10, 2012 8:00 PM
  • Where's the "I Like" when ones needed :)

    Saturday, August 11, 2012 11:00 AM
  • Another set of keystroke combinations that performs the same block commenting is:
    CTRL-E, C -- to comment out a block of code
    CTRL-E, U -- to un-comment a block
    Friday, November 30, 2012 9:15 PM