C#编码规范(1):命名规则
工作一段时间发现公司里代码的开发规范有很大的问题个人完全根据自己的喜好开发。
自己总结了下自己觉得比较合适的开发规范!
1. 类名,属性名,方法名,文件名 使用Pascal 大小写形式
2. 变量,方法参数 使用Camel 大小写形式
3. 用有意义的,描述性的词语来命名变量
- 别用缩写。用name, address, salary等代替 nam, addr, sal
- 别使用单个字母的变量象i, n, x 等. 使用 index, temp等
用于循环迭代的变量例外:
for ( int i = 0; i < count; i++ ){ ...}
如果变量只用于迭代计数,没有在循环的其他地方出现,许多人还是喜欢用单个字母的变量(i) ,而不是另外取名。
- 变量名中不使用下划线 (_) 。
- 命名空间需按照标准的模式命名
4. 文件名要和类名匹配
例如,对于类HelloWorld, 相应的文件名应为 helloworld.cs (或, helloworld.vb)
5. 三层命名规范
实体层:ClassInfo
数据层:DalClass (相同方法尽量统一命名) 如每个类中都 有Add Edit Delete 方法 得到数据前缀加 Get
业务逻辑层:BllClass
6.aspx文件命名规范
PageNameAdd
PageNameList
PageNameEdit
7.控件命名
| Control | Prefix | Example |
| Label | lbl | lblSurname |
| TextBox | txt | txtSurname |
| DataGrid | dg | dgResults |
| Button | btn | btnSave |
| ImageButton | ibtn | ibtnSave |
| Hyperlink | lnk | lnkHomePage |
| DropDownList | ddl | ddlCompany |
| ListBox | lst | lstCompany |
| DataList | dlst | dlstAddress |
| Repeater | rep | repSection |
| Checkbox | chk | chkMailList |
| CheckBoxList | chk | chkAddress |
| RadioButton | rdo | rdoSex |
| RadioButtonList | rdo | rdoAgeGroup |
| Image | img | imgLogo |
| Panel | pan | panSection |
| PlaceHolder | plh | plhHeader |
| Calender | cal | calMyDate |
| Adrotator | adr | adrBanner |
| Table | tbl | tblResults |
| [All] Validators | val | valCreditCardNumber |
| ValidationSummary | vals | valsErrors |
8 泛型命名规范
IList<ExhibitorInfo> ILExhibitorInfo = new List<ExhibitorInfo>()
Pascal 大小写形式-所有单词第一个字母大写,其他字母小写。
Camel 大小写形式-除了第一个单词,所有单词第一个字母大写,其他字母小写。

浙公网安备 33010602011771号