Comments in C#
Write single-line, multi-line, and XML documentation comments in C# — and understand how /// comments power IntelliSense tooltips.
Single-line Comments
1. Basic Single-line Comment
Use `//` to write a comment on its own line. Everything after `//` on that line is ignored by the compiler.
2. Inline Comment (End of Line)
Place a `//` comment at the end of a line to explain what that specific line does.
3. Debug Notes / TODOs
Use comments to leave TODO, FIXME, or HACK notes for yourself or your team. IDEs like Visual Studio highlight these.
Multi-line Comments
1. Basic Multi-line Comment
Use `/*` to start and `*/` to end a block comment. Everything in between is ignored by the compiler.
2. Temporarily Disable a Code Block
Wrap code in `/* */` to disable it without deleting it — useful when debugging.
3. Warning / Section Dividers
Use block comments as visual section dividers in large files to improve readability.
XML Documentation Comments (///)
1. Documenting a Method
Use `///` with XML tags like `<summary>`, `<param>`, and `<returns>` above a method. IDEs show this as a tooltip when you hover over the method call.
2. Documenting Exceptions
Use `<exception>` to document which exceptions a method may throw — helps callers know what to catch.
3. Useful XML Doc Tags
A reference of the most commonly used XML documentation tags in C#.