To use the full English descriptor that can accurately describe the variable/field/class, such as FirstName. For some of the obvious variables can be a simple name, such as the increment (minus) variable in the loop can be named "I".
Use the terminology in the areas covered by the project as much as possible.
To use a mixed case, improve the readability of the name. To distinguish multiple words in an identifier, capitalize the first letter of each word in the identifier. Do not use underscores for separating characters. There are two suitable writing methods that fit into different types of identifiers:
Pasalcasing: The letter of the first word of the identifier is capitalized;
CamelCasing: The letter of the first word of the identifier is lowercase.
The following table describes the casing rules for different types of identifiers:
Identifier |
Uppercase and lowercase |
Example |
Namespaces |
Pascal |
Namespace Com.Techstar.ProductionCenter |
Type |
Pascal |
public class Devslist |
Interface |
Pascal |
public interface Itablemodel |
Method |
Pascal |
public void UpdateData () |
Property |
Pascal |
public int length{...} |
Event |
Pascal |
public event EventHandler Changed; |
Private fields |
Camel |
private string FieldName; |
Non-private fields |
Pascal |
public string FieldName; |
Enumeration values |
Pascal |
Filemode{append} |
Parameters |
Camel |
public void UpdateData (string fieldName) |
Local variables |
Camel |
String FieldName; |
Avoid using abbreviations and use them sparingly if you have to use them. At the same time, you should keep a list of standard abbreviations and be consistent when you use them.
For common acronyms, the two-letter abbreviation should be in a uniform case (example: Iostream,getiostream), a multi-letter abbreviation in uppercase letters, and other lowercase letters (example: Gethtmltag);
Avoid the use of long names (preferably no more than 15 letters).
Avoid names that are similar or differ only in case.
6.2. Naming conventions for various identifier types
6.2.1. Assembly naming
Company domain name (techstar) + project name + module name (optional), for example:
Central system assembly: techstar.productioncenter;
Central system business logic assembly: Techstar. productioncenter.business;
6.2.2. Naming namespaces
In the same way that the assembly is named: Company domain name (techstar) + project name + module name. In addition, it is generally recommended that the namespace and directory structure be the same. For example:
Central system: techstar.productioncenter;
User controls under the central system: Techstar.ProductionCenter.UserControl;
Central system business logic: Techstar. productioncenter.business;
Central system data access: Techstar. Productioncenter.data;
6.2.3. Class and interface naming
The name of the class should be used as a noun;
Avoid using abbreviations for words, unless their abbreviations are widely known, such as HTTP.
The name of the interface must begin with the letter I. Ensure that the standard implementation of the interface name only one "I" prefix, for example, the standard implementation of IComponent for component;
Name of the generic type parameter: A descriptive name that is named T or begins with T, for example:
public class List<t>
public class Myclass<tsession>
For classes in different namespaces of the same project, naming avoids duplicates. Avoid conflicts and confusion when referencing;
6.2.4. Method naming
The first word is usually a verb.
If the method returns the value of a member variable, the method name is typically the get+ member variable name, and if the value returned is a bool variable, it is generally prefixed with IS. In addition, if necessary, consider the use of attributes to replace the method, the specific recommendations are shown in section 10.1.2;
If the method modifies the value of a member variable, the method name is generally: Set + member variable name. Ibid., consider using attribute to substitute method;
6.2.5. Variable naming
According to the scope of use, the variables in our code are basically the following types, the public variables of the class, the private variables of the class (protected and public), the parameter variables of the method, and the local variables used inside the method. The naming conventions for these variables are basically the same, see the identifier case comparison table. The difference is as follows:
The public variables of Class I are named in the usual way without special requirements;
Class II Private variables can be used in two ways: with "M" prefix, such as mworkername;
Iii. The parameter variables of the method are camalstring, for example Workername;
Iv. local variables within the method are camalstring, e.g. workername;
Do not use _ or & as the first letter;
Try to use short and meaningful words;
The variable names of single-character are generally used only for variables with very short lifetimes. I,j,k,m,n generally used for integer;c,d,e generally used characters;s for string
If the variable is a collection, the variable name is used in complex numbers. For example, the number of rows in a table should be named: Rowscount;
Naming components to use the Hungarian nomenclature, all prefixes should follow the same list of component name abbreviations
6.3. List of component name abbreviations
The basic principle of abbreviation is to take the first letter of each word of the component class name, and if there is only one word, remove the vowel and leave the consonant. Abbreviations are all lowercase.
Component type |
Abbreviation |
Example |
Label |
Lbl |
Lblnote |
Textbox |
Txt |
Txtname |
Button |
Btn |
Btnok |
ImageButton |
Ib |
IbOK |
LinkButton |
Lb |
Lbjump |
HyperLink |
Hl |
Hljump |
DropDownList |
Ddl |
Ddllist |
CheckBox |
Cb |
Cbchoice |
CheckBoxList |
Cbl |
Cblgroup |
RadioButton |
Rb |
Rbchoice |
RadioButtonList |
Rbl |
Rblgroup |
Image |
Img |
Imgbeauty |
Panel |
Pnl |
Pnltree |
Treeview |
Tv |
Tvunit |
Webcomtable |
Wct |
Wctbasic |
Imagedatetimeinput |
Dti |
Dtistart |
ComboBox |
Cb |
Cblist |
Myimagebutton |
Mib |
Mibok |
Webcomm.treeview |
Tv |
Tvunit |
Pagebar |
Pb |
Pbmaster |
Ext.: http://blog.csdn.net/beyond_winner/article/details/7637917
Basic Convention "Go" for C # naming