4 ms·
A common code style rule for C# is // for comments and //// for commented out code (/// is reserved for documentation generation). StyleCop analyzers can enforc
by logbiscuitswave 6y ago
A common code style rule for C# is // for comments and //// for commented out code (/// is reserved for documentation generation). StyleCop analyzers can enforce this during code analysis passes.
While this isn’t a language construct (a comment is a comment after all), Visual Studio can key off these stylistic differences to show code comments vs commented code differently. I find it to be a neat trick to improve code readability.
- jonnycomputer 6y agoCool. I've never touched C#. But that seems like an approach applicable pretty generally. I like it!
- CobsterLock 6y agoI thought //// was psuedo reserved for documentation. and then // was for general comments. I usually use block comments for commenting out code or I just use VS hotkeys which I think are //
- logbiscuitswave 6y agoIt’s actually /// (3 slashes) that reserved for pseudo-documentation use. There’s a StyleCop rule to enforce this as well: https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1626.md https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/ma...
- gnabgib 6y agoI've never seen this in C# code! How common is this? Do you have any references? Sounds like a useful convention (it's nigh impossible to google). VS only distinguishes between `///` (docblock) and all other (double, quadruple,quintuple, /*/). But maybe there's an extension.
- logbiscuitswave 6y agoHere’s more about commenting style: https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1515.md https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/ma... StyleCop is used for analyzing code style in C# code. Specifically: > If the comment is being used to comment out a line of code, begin the comment with four forward slashes rather than two. StyleCop relies on this to tell the difference between commented code and code comments. If you use ReSharper, it can do some nifty transformation to strike these out in the IDE which is kinda cool too. I’m a big fan of StyleCop to enforce consistent code styles. (Even if it’s not always what I may aesthetically prefer.)