C # code standards-naming conventions

Source: Internet
Author: User

naming conventions are determined before we write Code . This article is in idesign (www.idesign.net) A document circulating on the Internet (C # Coding Standard Version 2.1) .

Benefits of using naming conventions:

 In the Code DaquanIIThe authors explain the benefits of many naming conventions:

L requires you to follow more rules. By making a global decision rather than making many local decisions, you can focus on the more important features of the Code.

L helps deliver knowledge between projects. The similarity of names allows you to easily and confidently understand what unfamiliar variables should have done.

L helps you learn code faster in new projects. You don't need to know what specifications are in the code of other team members, but only need to face a group of more consistent code.

L helps reduce name growth. Without naming rules, it is easy to give two different names to the same object. This will confuse those who read this code.

L makes up for the shortcomings of programming language .

LEmphasize the relationship between related variables.

The key is that using any rule is better than having no rule. The existence of rules adds a structure for your code, reducing the amount of things you need to consider.

Naming rules:

1.UsePascalNaming classes and methods. The enumerated type ends with a plural number.

Public   Class Creditcard
{
Public StringGetcardname ()
}

2.UseCamelTo name local variables and method parameters. Its name should be irrelevant to the underlying data type and reflect the things represented by the variable.

Int Cardcount;
Public   String Getcardname ( String CardType)
{}

3.Interface prefix I.

Interface Iservice {}

4. Add the prefix cursor to the private member variable M _. use other parts of the name Pascal naming method.

Public   Class Creditcard
{
Private StringM_cardname;
}

5. Custom Attributes plus attributes attribute .
6. custom exception plus suffix exception .

7. the method is named by a verb-object phrase. For example, showdialog ()

8.The method name with a return value should contain a description of the return value.

9.Use meaningful variable names.

L do not use a single character as the variable name

L do not use Hungary name Public or protected member

LDo not Abbreviated Words

10.Use meaningful namespaces, such as product names and company names.

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.