I can't find answer anywhere regarding C# documentation comment, so please explain:
If I have a separate class and a method inside [someFunc()], then using /// Visual Studio will insert a documentation comment for the method.
namespace someNs
{
internal class someClass
{
/// <summary>
///
/// </summary>
public void someFunc()
{
}
}
}
But, if I have a method inside "static void Main(string[] args)" Then using /// does not work.
namespace someNs
{
internal class Program
{
static void Main(string[] args)
{
void someFunc()
{
}
}
}
}
Please explain why is it like that and is it possible some way to add the documentation comments?
Thank you.
CodePudding user response:
AFAIK the purpose of those comments is API documentation. someFunc()
is not part of any visible API of Program
; it's an implementation detail, so the feature you are asking for is a bit pointless.
Use regular comments to document what that particular piece of code does; whoever knows about someFunc
's existence and needs more information is reading your source code, so that should be enough.
CodePudding user response:
Comments having a certain form can be used to direct a tool to produce XML from those comments and the source code elements that they precede. Such comments are Single-Line_Comments that start with three slashes (///), or Delimited_Comments that start with a slash and two asterisks (/**). They must immediately precede a user-defined type or a member that they annotate. Attribute sections are considered part of declarations, so documentation comments must precede attributes applied to a type or member.
For expository purposes, the format of document comments is shown below as two grammar rules: Single_Line_Doc_Comment and Delimited_Doc_Comment. However, these rules are not part of the C# grammar, but rather, they represent particular formats of Single_Line_Comment and Delimited_Comment lexer rules, respectively.
Single_Line_Doc_Comment
: '///' Input_Character*
;
Delimited_Doc_Comment
: '/**' Delimited_Comment_Section* ASTERISK '/'
;
In a Single_Line_Doc_Comment, if there is a Whitespace character following the /// characters on each of the Single_Line_Doc_Comments adjacent to the current Single_Line_Doc_Comment, then that Whitespace character is not included in the XML output.
In a Delimited_Doc_Comment, if the first non-Whitespace character on the second line is an ASTERISK and the same pattern of optional Whitespace characters and an ASTERISK character is repeated at the beginning of each of the lines within the Delimited_Doc_Comment, then the characters of the repeated pattern are not included in the XML output. The pattern can include Whitespace characters after, as well as before, the ASTERISK character.