C#命名规范
原文:https://www.cnblogs.com/kubll/p/10788171.html
常用的命名规则:
Pascal(帕斯卡命名法)规则:每个单词开头的字母大写(如 TestApp).
Camel(驼峰)规则:除了第一个单词外的其他单词的开头字母大写. 如. testApp.
Upper(大写)规则:仅用于一两个字符长的常量的缩写命名,超过三个字符长度应该应用Pascal规则,例如:PI
|
标志符 |
规则 |
实例与描述 |
|
Namespace 命名空间 |
Pascal |
以“.”分隔,当每一个限定词均为Pascal命名方式,比如:using ExcelQuicker.Framework |
|
Class 类 |
Pascal |
不要使用类前缀 - 不要使用下划线字符 (_),例如:TestClass |
|
Function 方法 |
Pascal |
推荐名称应该为动词或动词短语,例如:AddElements |
|
Enum 枚举 |
Pascal |
Pascal命名,不要在 Enum 类型名称上使用 Enum 后缀,否则FXCop会抛出Issue |
|
Delegate 委托 |
Pascal |
以Pascal命名,不以任何特殊字符串区别于类名、函数名,命名的后面加EventHandler |
|
Interface 接口 |
Pascal |
使用字符I为前缀,并紧跟一个大写字母(即接口名的第一个字母大写),例如:IComponent |
|
自定义异常类 |
以Exception结尾 |
例如:public class AppException : Exception |
|
Const 常量 |
Pascal |
全部大写,单词间以下划线隔开 |
|
成员变量 |
Camel |
|
|
局部变量 |
Camel |
|
|
数据成员 |
Camel |
以m开头+Pascal命名规则,如mProductType(m意味member) |
总结:
- 命名空间,类,事件,接口,常量,属性,方法使用Pascal命名,即首字母大写
- 参数,变量(类字段)使用camel命名法,即首字母小写。
原文:https://www.cnblogs.com/lxxnet/archive/2006/08/07/470214.html
1 ADO.NET 命名规范
| 数据类型 | 数据类型简写 | 标准命名举例 |
| Connection | con | conNorthwind |
| Command | cmd | cmdReturnProducts |
| Parameter | parm | parmProductID |
| DataAdapter | dad | dadProducts |
| DataReader | dtr | dtrProducts |
| DataSet | dst | dstNorthWind |
| DataTable | dtbl | dtblProduct |
| DataRow | drow | drowRow98 |
| DataColumn | dcol | dcolProductID |
| DataRelation | drel | drelMasterDetail |
| DataView | dvw | dvwFilteredProducts |
2 WinForm Control 命名规范
| 数据类型 | 数据类型简写 | 标准命名举例 |
| Label | lbl | lblMessage |
| LinkLabel | llbl | llblToday |
| Button | btn | btnSave |
| TextBox | txt | txtName |
| MainMenu | mmnu | mmnuFile |
| CheckBox | chk | chkStock |
| RadioButton | rbtn | rbtnSelected |
| GroupBox | gbx | gbxMain |
| PictureBox | pic | picImage |
| Panel | pnl | pnlBody |
| DataGrid | dgrd | dgrdView |
| ListBox | lst | lstProducts |
| CheckedListBox | clst | clstChecked |
| ComboBox | cbo | cboMenu |
| ListView | lvw | lvwBrowser |
| TreeView | tvw | tvwType |
| TabControl | tctl | tctlSelected |
| DateTimePicker | dtp | dtpStartDate |
| HscrollBar | hsb | hsbImage |
| VscrollBar | vsb | vsbImage |
| Timer | tmr | tmrCount |
| ImageList | ilst | ilstImage |
| ToolBar | tlb | tlbManage |
| StatusBar | stb | stbFootPrint |
| OpenFileDialog | odlg | odlgFile |
| SaveFileDialog | sdlg | sdlgSave |
| FoldBrowserDialog | fbdlg | fgdlgBrowser |
| FontDialog | fdlg | fdlgFoot |
| ColorDialog | cdlg | cdlgColor |
| PrintDialog | pdlg | pdlgPrint |
3 WebControl 命名规范
| 数据类型 | 数据类型简写 | 标准命名举例 |
| AdRotator | adrt | Example |
| Button | btn | btnSubmit |
| Calendar | cal | calMettingDates |
| CheckBox | chk | chkBlue |
| CheckBoxList | chkl | chklFavColors |
| CompareValidator | valc | valcValidAge |
| CustomValidator | valx | valxDBCheck |
| DataGrid | dgrd | dgrdTitles |
| DataList | dlst | dlstTitles |
| DropDownList | drop | dropCountries |
| HyperLink | lnk | lnkDetails |
| Image | img | imgAuntBetty |
| ImageButton | ibtn | ibtnSubmit |
| Label | lbl | lblResults |
| LinkButton | lbtn | lbtnSubmit |
| ListBox | lst | lstCountries |
| Panel | pnl | pnlForm2 |
| PlaceHolder | plh | plhFormContents |
| RadioButton | rad | radFemale |
| RadioButtonList | radl | radlGender |
| RangeValidator | valg | valgAge |
| RegularExpression | vale | valeEmail_Validator |
| Repeater | rpt | rptQueryResults |
| RequiredFieldValidator | valr | valrFirstName |
| Table | tbl | tblCountryCodes |
| TableCell | tblc | tblcGermany |
| TableRow | tblr | tblrCountry |
| TextBox | txt | txtFirstName |
| ValidationSummary | vals | valsFormErrors |
| XML | xmlc | xmlcTransformResults |

浙公网安备 33010602011771号