I usually use // for comments, and I'm fine with writing detailed explanations when needed. Now that I'm working more with an existing C# codebase, I've started seeing
blocks above classes and methods. What are they used for, and when should I choose them instead of regular // comments? I initially assumed they were related to HTML because of the XML-like syntax.
3 Answers
These comments can be emitted into an XML documentation file when documentation generation is enabled. Tools can then use that file to build API documentation, and the information can travel alongside a compiled DLL so other projects still get descriptions for methods and parameters. NuGet libraries commonly include this kind of documentation.
They’re similar in spirit to Javadoc, JSDoc, Doxygen comments, and docstrings in other languages. In C#, typing /// immediately before a declaration usually makes the IDE generate a template with tags such as

That clears it up—thanks! I was seeing it in existing code and wasn’t sure whether it was just a different comment style.