Code writing specifications and naming conventions in C #

Source: Internet
Author: User

C # code writing rules:

1. use the interface as much as possible, and then use the class to implement the interface to improve program flexibility.

2. Do not exceed 80 characters in one line

3. Try not to manually change the computer-generated code

4. Write comments on key statements

5. Suggest that local variables are declared at the nearest place to use it

6. Do not use Goto series statements unless you are using it when jumping out of a deep loop

7. Avoid a method that uses more than 5 parameters.

8. Avoid writing try....catch modules with too much code

9. Avoid placing multiple classes in the same file

10. When building and building a long string, be sure to use the StringBuilder type instead of the string type

11.switch statements must have a default statement to handle unexpected situations

12. For the IF statement, use "{}" to enclose the statement block

13. Try not to use the This keyword reference

C # Naming conventions:

1. Using the Pascal rule to name the method and the type, the Pascal naming rule is that the first letter must be capitalized, and the first letter of the following concatenated words should be capitalized.

Eg:public class DataGrid;

2. Use the camel rule to name the parameters of the local variables and methods, with the first letter lowercase in the name

Eg:string strUserName;

3. Prefix "_" for all member variables

Eg:public class DataBase

{

private string _connectionstring;

}

4. Interface name prefixed with "I"

Eg:public interface IConvertible

{

byte ToByte ();

}

5. All member variables are declared at the top of the class, separated by a newline .

Eg:private class Product

{

private string _productld;

private string _productname;

}

6. When using the value of a control, name the local variable as much as possible

Eg:public string GetTitle ()

{

string title = Lbl_title.text;

return title;

}

Source: http://blog.csdn.net/hj_feiyoung/article/details/51146649

Code writing specifications and naming conventions in C #

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.