What is the purpose of documentation in C#?
Asked by
!try another angle
I've mostly used // for comments, and I don't mind writing fairly detailed explanations. However, while reviewing a larger C# codebase, I started seeing ... blocks above classes and methods. What are these used for, and when should I prefer them over regular // comments? Searches keep bringing up HTML-related results, so I'd appreciate an explanation of how C# XML documentation works.
Answers
Those are XML documentation comments. Visual Studio and other IDEs read them and display the text in tooltips and IntelliSense when someone hovers over a class or method. Theyโre especially useful for explaining the purpose of a public API without requiring someone to inspect the methodโs implementation. Regular // comments are still fine for notes about the codeโs internals.
Reply to this answer
XML documentation can be included in the compiled assemblyโs accompanying documentation file, which libraries and tools can use to generate API docs. Thatโs why many package libraries include descriptions for their types, methods, parameters, and return values. In Visual Studio, typing three forward slashes (///) immediately before a declaration usually generates a documentation template automatically.
Reply to this answer
Theyโre a standardized, tool-friendly form of comments. C# supports tags such as , , , and , and IDEs can format and link the information for you. Theyโre most valuable in larger projects and reusable libraries, where other developers may only see the API rather than the implementation.
Reply to this answer
Add your answer
Answers are reviewed before publication.
!try another angle: That clears it upโseeing the tags in a shared codebase made me think they were related to HTML. Iโll try using /// when documenting public methods.