二、代码格式化1.{}的位置 {与}各单独占一行。例如: if(x > 5) { //代码 }
2.if、if else的格式 if(condition) { DoSomething(); } if(condition) { DoSomething(); } else { DoSomethingOther(); } if(condition) { DoSomething(); } else if(condition) { DoSomethingOther(); } else { DoSomethingOtherAgain(); }3.for、foreach的格式 //for格式 for(int i = 0; i < 5; ++i) { // 代码 } //foreach的格式 foreach(int i in IntList) { // 代码 }4.while/switch的格式 //while格式 while(condition) { // 代码 } //switch的格式 switch(condition) { case A: ... break; case B: ... break; default: ... break; }5.try的格式 try { ... } catch(Exception e) { ... } //或者 try { ... } catch(Exception e) { ... } finally { ... }6.空格 对于有两个或两个以上空格时,一般不要使用空格来表示缩进,使用Tab 逗号、分号之后有一个空格 如:TestMethod(a, b, c); 操作符前后有一个空格,但是单目运算符除外(例如: !运算符)。 如:for(int i = 0; i < 10; ++i)7.在执行统一任务的各个语句组之间插入一个空行。8.名称空间写法,各类名称空间插入空行,同一类命命空间按字母序号排列 如: using System; using System.Text; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using net91com.Movies.DataAccess; using net91com.Movies.Business; using net91com.CommonComponent;