驼峰命名法
驼峰命名法(Camel-Case)是电脑程式编写时的一套命名规则(惯例)。
程序员们为了自己的代码能更容易的在同行之间交流,所以多才取统一的可读性比较好的命名方式。例如:有些程序员喜欢全部小写,有些程序员喜欢用下划线,所以如果要写一个my name的变量,他们常用的写法会有myname、my_name、MyName或者myName。这样的命名规则不适合所有程序员阅读,而利用驼峰命名法来表示,可以增加程序可读性。
驼峰命名法就是当变量名或函式名是由一个或多个单字连结在一起,而构成的唯一识别字时,第一个单字以小写字母开始;第二个单字的首字母大写或每一个单字的首字母都采用大写字母,例如:myFirstName、myLastName,这样的变量名看上去就像骆驼峰一样此起彼伏,故得名。
驼峰命名法(Camel-Case)一词来自 Perl 语言中普遍使用的大小写混合格式,而 Larry Wall 等人所著的畅销书《Programming Perl》(O'Reilly 出版)的封面图片正是一匹骆驼。
驼峰命名法的命名规则可视为一种惯例,并无绝对与强制,为的是增加识别和可读性。
数据库:
表名:首字母大写+驼峰式命名 eg:Article;UserDept
表中列名:首字母大写+驼峰式命名 eg:UserId;UnitCost
存储过程命名:表名_首字母大写+驼峰式命名 eg:Admin_UserRegister
项目名称:
公认简写:全部大写 eg:DAL;BLL
其他:首字母大写+驼峰式命名 eg:DBUtility;OracleDAL
类:
类名:首字母大写+驼峰式命名 eg:PetShop.cs;AssemblyInfo.cs
私有变量名:_首字母小写+驼峰式命名 eg:_publishTime;_rootCategoryId
公共属性名:首字母大写+驼峰式命名 eg:Description;PublishTime
函数:
函数名:首字母大写+驼峰式命名 eg:GetItemByProduct
参数名:首字母小写+驼峰式命名 eg:userId,itemInfo
C#控件命名规则
Control type prefix Example
Button btn btnOK
Grid grd grdPrices
3D Panel pnl pnlGroup
ADO Data ado adoBiblio
Animated button ani aniMailBox
Check box chk chkReadOnly
Combo box cbo cboEnglish
Dropdown list box ≥ ddl ddlUser
Command button cmd cmdExit
Common dialog dlg dlgFileOpen
Communications com comFax≤
Control (used within procedures when the specific type is unknown)
ctr ctrCurrent
Data dat datBiblio
Data-bound combo box dbcbo dbcboLanguage
Data-bound grid dbgrd dbgrdQueryResult
Data-bound list box dblst dblstJobType
Data combo dbc dbcAuthor
Data grid dgd dgdTitles
Data list dbl dblPublisher
Data repeater drp drpLocation
Date picker dtp dtpPublished
Directory list box dir dirSource
Drive list box drv drvTarget
File list box fil filSource
Flat scroll bar fsb fsbMove
Form frm frmEntry
Frame fra fraLanguage
Gauge gau gauStatus
Graph gra graRevenue
Hierarchical flexgrid flex flexOrders
Horizontal scroll bar hsb hsbVolume
Image img imgIcon
Image combo imgcbo imgcboProduct
ImageList ils ilsAllIcons
Label lbl lblHelpMessage
Lightweight check box lwchk lwchkArchive
Lightweight combo box lwcbo lwcboGerman
Lightweight command button lwcmd lwcmdRemove
Lightweight frame lwfra lwfraSaveOptions
Lightweight horizontal scroll bar lwhsb lwhsbVolume
Lightweight list box lwlst lwlstCostCenters
Lightweight option button lwopt lwoptIncomeLevel
Lightweight text box lwtxt lwoptStreet
Lightweight vertical scroll bar lwvsb lwvsbYear
Line lin linVertical
List box lst lstPolicyCodes
ListView lvw lvwHeadings
MAPI message mpm mpmSentMessage
MAPI session mps mpsSession
MCI mci mciVideo
Menu mnu mnuFileOpen
Month view mvw mvwPeriod
MS Chart ch chSalesbyRegion
MS Flex grid msg msgClients
MS Tab mst mstFirst
OLE container ole oleWorksheet
Option button opt optGender
Picture box pic picVGA
Picture clip clp clpToolbar
ProgressBar prg prgLoadFile
Remote Data rd rdTitles
RichTextBox rtf rtfReport
Shape shp shpCircle
Slider sld sldScale
Spin spn spnPages
StatusBar sta staDateTime
SysInfo sys sysMonitor
TabStrip tab tabOptions
Text box txt txtLastName
Timer tmr tmrAlarm
Toolbar tlb tlbActions
TreeView tre treOrganization
UpDown upd updDirection
Vertical scroll bar vsb vsbRate
asp.net控件命名规则
类型 |
前缀 |
示例 |
AdRotator |
adrt |
adrtTopAd |
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 |