In C/C ++ and JAVA, there are two types of Annotations: one is a single line annotation, that is, two backslash (//) and the other is a multiline annotation, it starts with/* and ends.
In Java, Multiline comments are divided into two forms:
1. Common multiline commentsFor example
Copy codeThe Code is as follows :/*
* Multi-line comment
*/
2. Javadoc commentsFor exampleCopy codeThe Code is as follows :/**
* Javadoc comments
*/
When the Java source file is compiled, the Javadoc tool reads the Javadoc comments in the source file and generates the corresponding HTML document. For developers to refer to API-related content.
XML is another form used in C.
To generate XML documents during compilation, You need to mark the annotations. That is, three backslash.
The following is a simple example:Copy codeThe Code is as follows: namespace MyNameSpace
{
/// <Summary>
/// This is a common class
/// </Summary>
Public class Person
{
/// <Summary>
/// This is the ID of the identifier
/// </Summary>
Public string Id {get; protected set ;}
/// <Summary>
/// This is the name
/// </Summary>
Public string Name {get; set ;}
/// <Summary>
/// This is the age
/// </Summary>
Public int Age {get; set ;}
/// <Summary>
/// This is the constructor.
/// </Summary>
/// <Param name = "id"> ID </param>
/// <Param name = "name"> name </param>
/// <Param name = "age"> age </param>
Public Person (string id, string name, int age)
{
This. Id = id;
This. Name = name;
This. Age = age;
}
/// <Summary>
/// Introduce Yourself
/// </Summary>
Public void IntroduceMyself ()
{
Console. WriteLine ("My name is {0}, My age is {1}", Name, Age );
}
/// <Summary>
/// Calculate the sum of the two
/// </Summary>
/// <Param name = "a"> left operand </param>
/// <Param name = "B"> right operand </param>
/// <Returns> and </returns>
Public int calculate (int a, int B)
{
Return a + B;
}
/// <Summary>
/// Speak
/// </Summary>
/// <Param name = "msg"> description </param>
Public void saySomething (string msg)
{
Console. WriteLine (msg );
}
}
}
Compile this file: csc/doc: test. xml test. cs
View the generated XML document:
Copy codeThe Code is as follows: <? Xml version = "1.0"?>
<Doc>
<Assembly>
<Name> MyNameSpace </name>
</Assembly>
<Members>
<Member name = "T: MyNameSpace. Person">
<Summary>
This is a common class
</Summary>
</Member>
<Member name = "M: MyNameSpace. Person. # ctor (System. String, System. String, System. Int32)">
<Summary>
This is the constructor
</Summary>
<Param name = "id"> ID </param>
<Param name = "name"> name </param>
<Param name = "age"> age </param>
</Member>
<Member name = "M: MyNameSpace. Person. IntroduceMyself">
<Summary>
Introduce yourself
</Summary>
</Member>
<Member name = "M: MyNameSpace. Person. calculate (System. Int32, System. Int32)">
<Summary>
Calculate the sum of the two
</Summary>
<Param name = "a"> left operand </param>
<Param name = "B"> right operand </param>
<Returns> the two and </returns>
</Member>
<Member name = "M: MyNameSpace. Person. saySomething (System. String)">
<Summary>
Speech
</Summary>
<Param name = "msg"> description </param>
</Member>
<Member name = "P: MyNameSpace. Person. Id">
<Summary>
This is the ID of the identifier
</Summary>
</Member>
<Member name = "P: MyNameSpace. Person. Name">
<Summary>
This is the name
</Summary>
</Member>
<Member name = "P: MyNameSpace. Person. Age">
<Summary>
This is age
</Summary>
</Member>
</Members>
</Doc>
If you are using visual studio, You must select the generate XML file in the project property generation tab and specify the path and file name.
In this way, when you use the corresponding class or method, we use the prompt tool provided by the IDE to view the class or the method briefly: