C# coding style: comments

后端 未结 10 1433
后悔当初
后悔当初 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:14

    There are a few reasons to prefer // to /*.. */.

    • As JaredPar mentioned, there are weird comment-nesting issues that can crop up with /* */ usage.
    • If you ever write/wrote some code that processes source code files, you'll be really happy if the // method is all that you have to deal with.
    • It is far easier to visually detect a large block of commented code with the "//" method, particularly if syntax coloring is unavailable. In fact, you'll often see the individual lines in a /* */ block prefixed with a *, just to be safe.
    • The XML commenting style that can be used to produce code documentation requires "///" to be used.

提交回复
热议问题