/// <summary> /// 类命名,公共开放给调用者的属性,字段,方法都应该使用PascalCasing方式 /// </summary> class Person { public string FirstName; public string LastName; public string Name { get { return string.Format("{0},{1}", FirstName, LastName); } } public string GetName() { return Name; } } /// <summary> /// 私有字段,变量都应该使用camelCasing方式 /// </summary> class Person { private string firstName; private string lastName; public string Name { get { return string.Format("{0},{1}", firstName, lastName); } } private int doSomeThing(int a ,int b) { int iTemp = 10 ; return a + b + iTemp ; } }
2 提供有意义的命名:
Person person=new Person(); 而不是 Person max = new Person();
1 class SampleClass 2 { 3 public void Init() 4 { 5 //本地初始化代码1 6 //本地初始化代码2 7 RemoteInit(); 8 } 9 public void RemoteInit() 10 { 11 12 } 13 } 14 应该重构为如下: 15 class SampleClass 16 { 17 public void Init() 18 { 19 LoadInit(); 20 RemoteInit(); 21 } 22 public void LoadInit() 23 { 24 //本地初始化代码1 25 //本地初始化代码2 26 } 27 28 public void RemoteInit() 29 { 30 31 } 32 }
时间: 2024-10-14 17:13:57