1)
用Pascal规则:
第一个字母必须大写,必须后面的连接词的第一个字母均为大写。
例如:
1: public void DataGrid
2: {
3:
4: }
2)
用Camel规则;
名称中第一个单词的第一个字母为小写,其他单词的第一个字符为大写。
例如:
1: string strUserName;
3)
所有的成员变量前加前缀“_”:
例如:
1: public class DataBase
2: {
3: private string _nameString;
4: }
4)
接口的名称加前缀“I”:
例如:
1: public class Iconvertible
2: {
3:
4: }
5)
方法的命名,一般将命名为动宾短语:
例如:
1: public class File
2: {
3: public void CreateFile(string filePath)
4: {
5:
6: }
7: }
6)
所有的成员变量申明在类的顶端。
1: public calss Student
2: {
3: private string _name;
4: private string _sex;
5: private int _age;
6:
7: public void ReadBook()
8: {
9: }
10: }
7)
使用某个控件的值时,尽量命名局部变量:
1: public string GetTile()
2: {
3: string title = lab_Title.Text;
4: return title;
5: }