Documentation comments turn source-level intent into structured information that tools can show to other developers. In C#, these comments are usually written with /// and can appear in IntelliSense, generated documentation, and editor tooltips.
/// <summary>/// Loads application settings from a JSON file./// </summary>/// <param name="filePath">The path to the settings file.</param>/// <returns>The loaded settings object.</returns>/// <exception cref="InvalidOperationException">/// Thrown when the file exists but cannot be parsed into valid settings./// </exception>AppSettings LoadSettings(string filePath){ throw new NotImplementedException();}
This helps a caller understand not only what the method does, but also what assumptions and failure conditions matter.
Documentation Comments
Documentation comments turn source-level intent into structured information that tools can show to other developers. In C#, these comments are usually written with
///and can appear in IntelliSense, generated documentation, and editor tooltips.Original Microsoft Learn reference: Recommended XML tags for C# documentation comments.
They matter most when an API should be understandable without forcing the reader to open the implementation.
Why they matter in practice
Good documentation comments help answer questions such as:
This is especially useful for reusable methods, libraries, shared utilities, and public APIs inside a team codebase.
A basic example
This is simple, but real documentation comments are most useful when the behavior is not already obvious from the name alone.
Common XML tags
Some of the most common documentation comment tags are:
<summary>for the main purpose<param>for parameter descriptions<returns>for return value meaning<exception>for documented thrown exceptions<remarks>for extra guidance or detailsA more practical example
This helps a caller understand not only what the method does, but also what assumptions and failure conditions matter.
A mental model
Documentation comments are mainly for API consumers, not for restating the implementation line by line.
What good documentation comments describe
The best comments usually explain:
They are less useful when they only repeat the method name in slightly different words.
When comments add real value
Documentation comments are especially valuable for:
When comments are weak
This kind of comment usually adds little value:
That mostly repeats what the method name already says.
Better documentation explains what kind of name, what rules apply, and what happens if the input is invalid.
Common beginner mistakes
Summary
///Practice
Write a documentation comment for a method that reads a configuration file and returns parsed settings.
As a second exercise, take one weak summary comment and rewrite it so it explains a real behavioral rule or failure condition.