C # Coding specifications summarized by myself-4. annotation conventions

Source: Internet
Author: User
  • Note

Note is undoubtedly the fastest way to let others know your code as quickly as possible, but the purpose of writing a comment is not just to "explain what the code has done ", more importantly, try to help the code reader understand the code as much as the author does.

When you write code, there will be a lot of valuable information in your mind, but when others read your code, this information has been lost, and all they see is the current code.

  • Annotations

If the IDE provides the annotation format, try to use the format provided by the IDE; otherwise, use "//" to annotate. Class, attribute, and method annotations use the format automatically generated by input "//" in Visual Studio.

  • Class annotation conventions

/// <Summary>

/// Class description

/// </Summary>

Public class binarytree

  • Class property annotation conventions

/// <Summary>

/// Attribute description

/// </Summary>

Public int nodescount {Get; private set ;}

  • Method annotation Convention

/// <Summary>

/// Method description

/// </Summary>

/// <Param name = "parentnode"> parameter description </param>

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

Public int computechildnodescount (binarynode parentnode)

  • Comments between codes
  1. Single line comment, comment rows <3 rows use

    // Single line comment

  2. Multi-line comment, used when 2 <comment rows <= 10

    /* Multi-line comment 1

    Multi-line comment 2

    Multi-line comment 3 */

  3. Comment block, 10 <used to comment the number of rows, 50 *

    /*************************************** ************

    * Code block comment 1

    * Code block comment 2

    *......

    * Code block Comment 10

    * Code block comment 11

    **************************************** ***********/

  • Conventions on when to write comments
  1. In the following three cases, all classes, class attributes, and methods must be annotated according to the preceding format.
    1. The client attaches great importance to code comments.
    2. We need to provide the API documentation automatically generated by code annotations.

    1. Currently, the public core module is written.
  2. If the customer does not have special requirements for the annotations, add the annotations as discussed below. Do not add unnecessary comments.

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.