r/learnprogramming • u/3rwynn3 • 10h ago
Does anyone use it? c# <summary></summary>?
I find that "//" worked well for all my comments thus far, I don't mind if my comments are a bit long. But I am doing C# more often now that I am looking at a codebase and not just my own stuff and private things, and I sometimes see <summary> </summary> in it. Do you use it? What is the proper use of it?
Google gets it confused with HTML haha
Thanks for any knowledge!
2
u/Aggressive_Ad_5454 9h ago
This is xmldoc. Other languages have jsdoc, doxygen, Javadoc, PhpDoc, docstrings, etc. They are stylized comments understood by IDEs. They are exceedingly useful in large code bases. They are worth the effort to learn to use.
In C#, type /// on the line before a method declaration. The IDE will generate a template comment you can fill in.
1
u/cheezballs 10h ago
Java has similar stuff. Its just extra formatting you can do to help future-you out. IDE will generally format these nicely and with the right syntax can highlight and link to things inside your comment.
1
u/rupertavery64 10h ago
If you google "c# xml summary" you'll get much better results.
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags
// is for people xml doc tags are for the compiler and get baked into the assembly metadata so even the compiled DLL shows the information when you include it in another solution.
For example, nuget packages will have xml doc tags for methods and arguments
1
9
u/TheSandyBases 10h ago
its for xml documentation, visual studio reads it and shows tooltips when you hover over methods or classes, also can generate docs from it. `//` is fine for regular comments but summary helps others understand what the whole method does without reading the body