1.1命名规范 1.1.1利用Pascal的方式定义类型、方法名和常量 public class SomeClass { const int DefaultSize = 100; public SomeMethod() {} } 1.1.2对于局部变量和方法的参数使用骆驼命名法 int number; void MyMethod(int someNumber) {} 1.1.3接口的名称前加上I interface IMyInterface {…} 1.1.4 在私有成员变量前面加上m_。对于m_ 后面的变量名使用骆驼命名方法 public class SomeClass { private int m_Number; } 1.1.5 对自定义的属性类加上后缀Attribute 1.1.6 对自定义的异常类加上后缀Exception 1.1.7 方法的命名使用动词—对象对,例如ShowDialog() 1.1.8 有返回值的方法的命名中要有返回值的描述,例如GetObjectState()
Identifier Case Example Class Pascal AppDomain Enum type Pascal ErrorLevel Enum values Pascal FatalError Event Pascal ValueChange Exception class Pascal WebException Note Always ends with the suffix Exception. Read-only Static field Pascal RedValue Interface Pascal IDisposable Note Always begins with the prefix I. Method Pascal ToString Namespace Pascal System.Drawing Parameter Camel typeName Property Pascal BackColor Protected instance field Camel redValue Note Rarely used. A property is preferable to using a protected instance field. Public instance field Pascal RedValue Note Rarely used. A property is preferable to using a public in
1.1.1利用Pascal的方式定义类型、方法名和常量
public class SomeClass
{
const int DefaultSize = 100;
public SomeMethod()
{}
}
1.1.2对于局部变量和方法的参数使用骆驼命名法
int number;
void MyMethod(int someNumber)
{}
1.1.3接口的名称前加上I
interface IMyInterface
{…}
1.1.4 在私有成员变量前面加上m_。对于m_ 后面的变量名使用骆驼命名方法
public class SomeClass
{
private int m_Number;
}
1.1.5 对自定义的属性类加上后缀Attribute
1.1.6 对自定义的异常类加上后缀Exception
1.1.7 方法的命名使用动词—对象对,例如ShowDialog()
1.1.8 有返回值的方法的命名中要有返回值的描述,例如GetObjectState()
Identifier Case Example
Class Pascal AppDomain
Enum type Pascal ErrorLevel
Enum values Pascal FatalError
Event Pascal ValueChange
Exception class Pascal WebException
Note Always ends with the suffix Exception.
Read-only Static field Pascal RedValue
Interface Pascal IDisposable
Note Always begins with the prefix I.
Method Pascal ToString
Namespace Pascal System.Drawing
Parameter Camel typeName
Property Pascal BackColor
Protected instance field Camel redValue
Note Rarely used. A property is preferable to using a protected instance field.
Public instance field Pascal RedValue
Note Rarely used. A property is preferable to using a public in
Label lbl△○○
TextBox txt△○○
MaskedTextBox txt△○○
NumberBox txt△○○
Xcontrols、System.Windows.Forms.DateTimePicker txt△○○
RadioButton rdb△○○
CheckBox chk△○○
ComboBox cmb△○○
DataGridView dgv△○○
Panel pnl△○○
GroupBox grp△○○
Button btn△○○
TabControl tab△○○※ 「△」大些字母的设定。
※ 「△○○」根据数据库说明书中表中列项ID确定。
※ 控件命名要表明控件的功能,或对应的对象。如删除按钮 btnDelete。除非一些特定缩写,尽量不要用略写,如btnDel。
方法 命名: Pascal规范 动词或动词短语
public void Print() {...}
public void ProcessItem() {...} 综合命名规范
一定请 为各种类型,函数,变量,特性和数据结构选取有意义的命名。其命名应能反映其作用。 您不应该在标识符名中使用缩短或缩略形式的词。比如,使用 “GetWindow” 而不是 “GetWin”。对于公共类型,线程过程,窗口过程,和对话框过程函数,为“ThreadProc”, “DialogProc”, “WndProc” 等使用公共后缀。 一定不要 使用下划线,连字号,或其他任何非字母数字的字符。