<h2>1.空白</h2><p style="margin-left:30px;">这个没啥好说的,意思就是该留空白的时候要果断留,不要怕浪费。空白有助于提高代码的可读性。</p><h2>2.块</h2><p style="margin-left:30px;">一般表示用大括号“{”和“}”括起来的部分。</p><h2>3.驼峰法(小驼峰法)</h2><p style="margin-left:30px;">变量一般用小驼峰法标识。驼峰法的意思是:除第一个单词之外,其他单词首字母大写。譬如</p><div style="margin-left:30px;"><pre>int myStudentCount;</pre></div><p style="margin-left:30px;">变量myStudentCount第一个单词是全部小写,后面的单词首字母大写。</p><div style="page-break-after: always;"><span style="display: none;"><!--more-->& nbsp ;</span></div><h2>4.Pascal法(大驼峰法)</h2><p style="margin-left:30px;">相比小驼峰法,大驼峰法把第一个单词的首字母也大写了。常用于类名,函数名,属性,命名空间。譬如</p><div style="margin-left:30px;"><pre>publicclass DataBaseUser;</pre></div><p> </p><h2>5.全局变量</h2><p style="margin-left:30px;">一般惯例是加一个前缀或者后缀用于私有变量和局部变量。通常是用下划线“_”来标识。譬如</p><div style="margin-left:30px;"><pre>privateint myStudentCount_;</pre></div><p> </p><p style="margin-left:30px;">下划线有加在前面的,也有加在后面的。个人比较习惯加在前面。</p><h2>6.常量</h2><p style="margin-left:30px;">常量通常用全大写,并用下划线来分割单词来标志。譬如</p><div style="margin-left:30px;"><pre>privateintconst STUDENT_COUNT=50;</pre></div><p> </p><h2>7.switch</h2><p style="margin-left:30px;">用switch的时候,无论case是否涵括了所有情况,都应该加上Default语句。很多时候结果是不再我们考虑范围内的。应该尽量涵盖所有情况。譬如</p><div style="margin-left:30px;"><div>复制代码</div><pre>switch(month) { case1: //...break; case2: //...break; ... case12: //code...break; default: //code...break; }</pre><div>复制代码</div></div><p> </p><p style="margin-left:30px;">代码用于处理每个月的不同情况,虽然已经处理了十二个月的情况,但是代码还是加上了default用于以防万一,这是值得推荐的。</p><h2>8.二元运算符</h2><p style="margin-left:30px;">一般在二元运算符左右需要加一个空格。当然用VS的人一般都知道当你打出每一句代码的最后标志符“;”的时候,VS会自动处理代码,给二元运算符的左右加上一个空格。譬如</p><div style="margin-left:30px;"><pre>count = count + i;</pre></div><p> </p><p style="margin-left:30px;">可以发现在“=”和“+”左右都是有一个空格的。这样比起不加空格确实好看很多。不信,你别加试试。</p><h2>9.条件语句</h2><p style="margin-left:30px;">添加语句上面尽量不要用直接值。譬如</p><div style="margin-left:30px;"><pre>int count = 60; if(count_ >= count) { //code...}</pre></div><p> </p><p style="margin-left:30px;">我们推荐这种做法,我们不推荐</p><div style="margin-left:30px;"><pre>if(count_ >= 60) { //code...}</pre></div><p> </p><p style="margin-left:30px;">这种做法。当要发生修改的时候,前者的价值就相当明显了。</p><h2>10.使用别名</h2><p style="margin-left:30px;">尽量使用类型名的别名。例如</p><div style="margin-left:30px;"><pre>int count = 60; System.Int32 count2 = 60;</pre></div><p> </p><p style="margin-left:30px;">其实int只是System.Int32的别名而已,两者产生的效果作用是一模一样的。不过我们推荐使用前者,不推荐后者。这有历史的因素吧,不过只要是个人,都会很自觉写int,double这些别名吧。</p><h2>11.原子方法</h2><p style="margin-left:30px;">我们推荐原子操作。一个函数不需要做太多的事情。特别是对于类来说。如果一个实现可以用几个原子方法来完成,我们推荐这种做法,而不推荐把方法写地太长。最好别超过100行。</p><h2>12.访问控制标志</h2><p style="margin-left:30px;">虽然可以默认不填写访问控制符。但是我们不推荐这种做法。我们推荐把类里面所有的变量,方法,属性,...都写上访问权限。</p><h2>13.region</h2><p style="margin-left:30px;">#region和#endregion是非常好用的东西。它可以在任何位置,无聊是否在同时在同一个块内,都可以使用,将代码收缩。在一个类里面,我们推荐使用region将代码分类。譬如</p><p style="margin-left:30px;"></p></div>