摘录自胡子随想的Blog,由于不知道怎么使用TrackBack ,所以就直接copy过来了,对原作者说声抱歉了。
原文地址:http://coolbo.blogbus.com/logs/2005/10/1542477.html
编码规则
<!--[if !supportLists]-->1. <!--[endif]-->名称空间 NameSpace
<!--[if !supportLists]-->① <!--[endif]-->公司名.产品名[.组件名的复数]
<!--[if !supportLists]-->② <!--[endif]-->Ms.Office
<!--[if !supportLists]-->2. <!--[endif]-->类型级命名
<!--[if !supportLists]-->① <!--[endif]-->类 [Class]
<!--[if !supportLists]-->n <!--[endif]-->Form类以Form结尾 | Class MainForm
<!--[if !supportLists]-->n <!--[endif]-->Web类以Page结尾 | Class ProductListPage
<!--[if !supportLists]-->n <!--[endif]-->名词或者名词短语 | Class Indicator
<!--[if !supportLists]-->n <!--[endif]-->当类是特性时以Attribute结尾 | Class CauseExceptionAttribute
<!--[if !supportLists]-->n <!--[endif]-->当类是异常时以Exception结尾 | Class ColorSetException
<!--[if !supportLists]-->n <!--[endif]-->当类只作为基类以Base结尾 | Class IndicatorBase
<!--[if !supportLists]-->n <!--[endif]-->当类只会存在一个实例(全局类类)以Class结尾 | Class ApplicationSystemClass
<!--[if !supportLists]-->n <!--[endif]-->不要使用下划线字符
<!--[if !supportLists]-->n <!--[endif]-->少用缩写
<!--[if !supportLists]-->② <!--[endif]-->枚举 [Enum]
<!--[if !supportLists]-->n <!--[endif]-->以名词或名词短语命名
<!--[if !supportLists]-->n <!--[endif]-->以复数结尾
<!--[if !supportLists]-->n <!--[endif]-->Colors Keys
<!--[if !supportLists]-->③ <!--[endif]-->接口 [Interface ]
<!--[if !supportLists]-->n <!--[endif]-->由I作为前缀,并用形容词命名
<!--[if !supportLists]-->n <!--[endif]-->Interface ISortable
<!--[if !supportLists]-->④ <!--[endif]-->结构 [Structure ]
<!--[if !supportLists]-->⑤ <!--[endif]-->委托 [Delegate ]
<!--[if !supportLists]-->n <!--[endif]-->以描述动作的名词命名
<!--[if !supportLists]-->n <!--[endif]-->用于事件处理的委托类型,必须以EventHandler结尾
<!--[if !supportLists]-->3. <!--[endif]-->方法&属性
<!--[if !supportLists]-->① <!--[endif]-->方法 [Method]
<!--[if !supportLists]-->n <!--[endif]-->必须以动词或动词短语命名
<!--[if !supportLists]-->② <!--[endif]-->属性 [Property]
<!--[if !supportLists]-->n <!--[endif]-->属性以简洁清晰的名词命名
<!--[if !supportLists]-->③ <!--[endif]-->事件 [Event]
<!--[if !supportLists]-->n <!--[endif]-->命名的原则一般是动词或动词的分词,通过时态表明事件发生的时间
<!--[if !supportLists]-->4. <!--[endif]-->变量&常数
<!--[if !supportLists]-->① <!--[endif]-->常数 [Const]
<!--[if !supportLists]-->n <!--[endif]-->常数以表明常数意义的名词命名,一般不区分常数的类型
<!--[if !supportLists]-->n <!--[endif]-->全部使用大写字母 | Const String DEFAULT_NAME
<!--[if !supportLists]-->n <!--[endif]-->字之间用下划线分隔
<!--[if !supportLists]-->② <!--[endif]-->变量 [Variable]
<!--[if !supportLists]-->n <!--[endif]-->用有意义的名字命名即可
<!--[if !supportLists]-->n <!--[endif]-->用相应的数据类型简写开头
<!--[if !supportLists]-->n <!--[endif]-->Private String strCustomerName
<!--[if !supportLists]-->n <!--[endif]-->Private int iCustomerCount
<!--[if !supportLists]-->n <!--[endif]-->常用数据类型缩写
bool b
Array arr
Byte byt
Char chr
DateTime dtm
Decimal dec
Double dbl
int i
Long lng
Object obj
Short shr
Single sng
String str
<!--[if !supportLists]-->n <!--[endif]-->属性所对应的变量
以m_开头 | Private String m_ProductName
private String m_ProductName
public String ProductName
{
get
{
retrun m_ProductName;
}
}
<!--[if !supportLists]-->n <!--[endif]-->不要使用原义数字或原义字符串
例如
for(int i = 50;i < 100;i ++)
{
MessageBox.Show(i.ToString());
}
应该如此:
for(int i = iStart;i < iEnd;i ++)
{
MessageBox.Show(i.ToString());
}
<!--[if !supportLists]-->n <!--[endif]-->使用命名常数
<!--[if !supportLists]-->n <!--[endif]-->常用控件缩写
Label lbl
Button btn
LinkButton lnk
TextBox txt
CheckBox chk
ListBox lst
DropDownList drp
DataGrid dgrd
More ...
<!--[if !supportLists]-->5. <!--[endif]-->注释 [commentary]
<!--[if !supportLists]-->① <!--[endif]-->类的注释
<!--[if !supportLists]-->n <!--[endif]-->类的开始
/// <summary>
/// 名称:DataAccess
/// 依赖关系: System.Data,System.Data.SqlClient
/// 目的:实现数据操作
/// 参数:
/// 创建人:Coolbo
/// 创建时间:2005-10-26
/// 注释:数据返回应该考虑再完善些
/// </summary>
名称
依赖关系
目的
作者
参数
最后编辑人
最后编辑时间
注释
<!--[if !supportLists]-->n <!--[endif]-->类的修改
/// <summary>
/// 名称:DataAccess
/// 依赖关系: System.Data,System.Data.SqlClient
/// 目的:实现数据操作
/// 参数:
/// 创建人:Coolbo
/// 创建时间:2005-10-26
/// 注释:数据返回应该考虑再完善些
/// 修改描述:用SqlClient类替代了原来的OLEDB类操作数据库
/// 修改者:Kevin
/// 修改日期:2005-11-20
/// </summary>
修改描述
修改者
修改日期
<!--[if !supportLists]-->② <!--[endif]-->类属性
/// <summary>
/// 属性的描述
/// </summary>
<!--[if !supportLists]-->③ <!--[endif]-->方法
/// <summary>
/// 对类方法的说明性描述
/// </summary>
/// <param name="参数名称">参数说明</param>
/// <returns>
/// 对方法返回值的说明,该说明必须明确说明返回的值代表什么含义
/// </returns>
<!--[if !supportLists]-->n <!--[endif]-->说明
<!--[if !supportLists]-->n <!--[endif]-->参数
<!--[if !supportLists]-->n <!--[endif]-->参数说明
<!--[if !supportLists]-->n <!--[endif]-->对方法返回值的说明,该说明必须明确说明返回的值代表什么含义
<!--[if !supportLists]-->④ <!--[endif]-->代码间说明
<!--[if !supportLists]-->n <!--[endif]-->代码中遇到语句块时必须添加注释(if,for,foreach,……),添加的注释必须能够说明此语句块的作用和实现手段(所用算法等等)
<!--[if !supportLists]-->6. <!--[endif]-->代码格式
<!--[if !supportLists]-->① <!--[endif]-->缩进用Tab缩进,使用vs默认
<!--[if !supportLists]-->② <!--[endif]-->在代码中垂直对齐左右括号()除外
for(int i = 0;i < 10;i ++)
{
MessageBox.Show(i.ToString());
}
<!--[if !supportLists]-->③ <!--[endif]-->单行代码或者注释不得超过1024*768分辨率下的一屏
<!--[if !supportLists]-->④ <!--[endif]-->当一行被分为几行时,通过将串联运算符放在每一行的末尾而不是开头
<!--[if !supportLists]-->⑤ <!--[endif]-->每一行上放置的语句避免超过一条
<!--[if !supportLists]-->⑥ <!--[endif]-->在大多数运算符之前和之后使用空格 | int i = i + k;
<!--[if !supportLists]-->⑦ <!--[endif]-->将大的复杂代码节分为较小的、易于理解的模块
<!--[if !supportLists]-->⑧ <!--[endif]-->编写 SQL 语句时,对于关键字使用全部大写,对于数据库元素(如表、列和视图)使用大小写混合
<!--[if !supportLists]-->⑨ <!--[endif]-->将每个主要的 SQL 子句放在不同的行上
SELECT FirstName, LastName
FROM Customers
WHERE State = 'WA'