C# coding style: comments

后端 未结 10 1426
后悔当初
后悔当初 2021-01-17 15:59

Most C# style guides recommend against the /* ... */ commenting style, in favor of // or ///. Why is the former style to be avoided?

相关标签:
10条回答
  • 2021-01-17 16:28

    /* */ is fine for multi-line code blocks. For instance at the top of a code file, copyright info etc.

    // is easier for single line.

    Always use /// for at least all public members in a class as your XML documentation gets generated from that from which you can create help files.

    0 讨论(0)
  • 2021-01-17 16:30

    One example that comes to mind is that it's possible to accidentally interrupt a /* style comment. For example

    /* This is the start of a comment that documents the 
       behavior of the +-*/ operators in our program
    */ 
    

    This code does not compile, while the // variant would. Also the /// represents a specific style of documentation to which external tools respond differently.

    0 讨论(0)
  • 2021-01-17 16:36

    My guess is because one requires explicit syntax on EACH line and one creates comments that can comment out large sections of code if the closing */ is not used. It's just not as safe.

    0 讨论(0)
  • 2021-01-17 16:39

    My opinion is that "//" is just easier to type in than /**/

    0 讨论(0)
提交回复
热议问题