Comments to the C # tutorial

Source: Internet
Author: User

In C # code, another common statement is annotation. Annotations are not strictly C # code, but it is best to annotate the code. Annotation is an explanation, that is, adding descriptive text to the code

  

The compiler ignores this content (in this series of SQL Server 2008 books, it also details why annotations should be used ). When you start to process long code segments, annotations can be used to add prompts to ongoing work. For example, in the two instances in the first chapter of this book, we have written comments on our own code. C # There are two ways to add annotations. You can place the "/*" and "*/" tags at the beginning and end of the comment, or use a tag "//" as in the instance of the previous chapter "//", however, you cannot wrap a line when using this method. That is to say, a // symbol can only represent a comment row.

  

To mark a comment in the first way, you can add "/*" at the beginning of the comment and "*/" at the end "*/". These annotation symbols can be on a single line, or on different lines. All the contents between the annotation symbols are comments.

  

In C #, This annotation method is often used for the general description of a class scheme. The comment at the top of the Code Below is a description of the current file:

  

/*----------------------------------------------------------------------------------

  

* Copyright Description: This code file is *** copyrighted, without the company

  

* Anyone or company authorized in writing shall not use part or whole of this sow

  

* Unit name: Guide_Star

  

* Unit description: class star services for tour guides, which are used to perform SIDU operations on tour guides;

  

* Provides a list of tour guides for different stars;

  

* Business logic of star-Level Rules;

  

* Created by: Laotian

  

* Release: 1.0

  

* Creation date:

  

* ---------------- Modify the log -------------------------

  

* Modified by date

  

* Add a query method based on any field in day

  

----------------------------------------------------------------------------------*/

  

Using System;

  

Using System. Data;

  

{

  

/// <Summary>

  

/// Star services of tour guides.

  

/// </Summary>

  

PublicclassGuide_Star

  

{

  

// This is the second method of commenting on a single sentence

  

Privatereadonly LonelyBag. DAL. Guide_Star dal = new LonelyBag. DAL. Guide_Star ();

  

Public Guide_Star ()

  

{}

  

Member method code

  

}

  

}

  

Another way to add a comment is to start a comment with "//", and then you can write any content as long as the content is on one line. The following statement is correct, for example, in the code above

  

// This is the second method of commenting on a single sentence

  

The following statement fails because the second line of code is interpreted as C # code:

  

// This is the second annotation method,

  

Comments to a single sentence

  

This type of comment can be used to describe a separate line of C # statements, because they are all placed on one line:

  

Xiaotian: In your instance, I still see this comment. What does it mean?

  

  

  

/// <Summary>

  

/// Star services of tour guides.

  

/// </Summary>

  

Lao Tian: This is the third comment of C #. Strictly speaking, this is an extension of the // syntax. They are all single-line comments starting with three "/" symbols, rather than two.

  

This method is mainly used to describe the Class and Class Members, and is easier to use than the first one (before and after use. Place the cursor in the place where this annotation needs to be added, and hit three "/" consecutively. If it is a class description, the above form will be generated. If it is a method, a more detailed comment format will be automatically generated based on the method parameters and return types.

  

Under normal circumstances, the compiler ignores them, just like other annotations, but VS can be configured to extract the text after these annotations during project compilation, create a text file in special format, which can be used to create a text inventory manual.

  

Xiaotian: What does the summary in the angle brackets mean?

  

Laotian: This is the XML tag of this annotation. The following table describes the XML tag and its function.

  

Tag description

  

<C> mark the code in the row as Code, for example, <c> if (I> = 10); </c>

  

<Code> MARK multiple lines as code

  

<Example> mark as a sample code

  

<Exception> indicates an exception class.

  

<Include> annotations containing other document descriptions

  

<List> Insert the list to the text description

  

<Para> MARK parameters of a Method

  

<Param> <param name = 'name'> description </param>

  

Name is the Name of the parameter in the method, and description is the description of the Parameter

  

<Paramref> indicates that a word is a method parameter.

  

<Permission> access to members

  

<Remarks> Add a description to a member

  

<Returns> return value of the Method

  

<See> provides cross-reference for another parameter

  

<Seealso> "see" section in the description

  

<Summary> provides a brief summary of types or members.

  

<Typeparam> the text is displayed in the intelliisense of the Web Report annotated by the Object Browser code.

  

<Typeparam name = "name"> description </typeparam>

  

Name is the parameter Name, and description is the parameter description

  

<Typeparamref> Users of 文 can set the Word format in a unique way, for example, in italic.

  

<Typeparamref name = "name"/>

  

Name is the Name of the type parameter.

  

<Value> description attribute

  

Next, let's take a specific example. In the following example, all the symbols and fonts except gray are automatically generated after "three consecutive times on the method body"/", so you don't need to think too much.

  

/// <Summary>

  

/// Brief description of this method

  

/// </Summary>

  

/// <Param name = "min"> description of the parameter min </param>

  

/// <Param name = "max"> description of the max parameter </param>

  

/// <Returns> return value description </returns>

  

Publicint GetCount (int min, int max)

  

{

  

// Play with you

  

}

  

This article is a new one. For more information, see the source and author!

  

  

  

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.