C # Coding specifications summarized by myself-6. Format

Source: Internet
Author: User
Tags word wrap

C # Coding specifications summarized by myself-6. Format
The unified use of the format can make the code clear, beautiful, and easy to read. In order not to affect the encoding efficiency, the following rules should be made: the length of a file should not exceed 500 lines (except the class automatically generated by the IDE ). A file must have only one namespace. It is strictly prohibited to put multiple namespaces in one file. It is best to have only one class for a file. If there are more than 500 rows, consider splitting the category or using the Partial class to split the class by function. The code of a method should not exceed 50 lines. If the Code exceeds 50 lines, consider encapsulating the logic in it into a function. The use of spaces and empty lines is based on the principle that the code is clear. Empty lines affect program running, but can make the Code look clear and increase readability, so it can be used as appropriate. There is a blank line between the method and the method between the variable declaration in the function and the internal logic of the function. After a logic inside a function is complete, there must be an empty line, and then write a new line feed. The principle is not to make a line of code very long, so that readers can read it quickly. Ask all team members to enable the Visual Studio automatic line feed function. Tools-> Options-> Text Editor-> C #-> Check the Word wrap CheckBox to keep it within 80 columns without causing serious ambiguity or increasing reading difficulty, up to 120 columns are allowed for easy reading and code printing. In addition, the line feed principle is that after a comma, the line feed before the operator, line feed and the first line should maintain a unit of indentation. "{" And "}" must be on a single line and aligned up and down. If, while, do, try-catch-finaly and other statements must be followed by {}, even If there is only one statement or the statement is empty, and follow the rules that "{" and "}" must be on a single line. The use of Region can clearly define the scope of the code block and provide corresponding comments. Therefore, we recommend that you use Region as much as possible. At the same time, Region can also be used to organize the code structure. We use the following Region Convention to make the Organization class: A class should use Region to divide Fields, Properties, Constructor, Private Methods, and Protected & Public Methods. And arranged from top to bottom in the above Order. Fields, Properties, Constructor, and Private Methods must be placed in Region. Protected & Public Methods must be placed outside. Protected & Public Methods is the most frequently used content by code readers. This allows code readers to use Ctrl + M to locate the content they want as quickly as possible.

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.