`
hmfcr11l
  • 浏览: 11078 次
社区版块
存档分类
最新评论

C#命名规范

阅读更多

  本文的结构为:(1)C#常用三种命名方法、(2)代码规范、(3)数据类型规范、(4)控件规范
  (1)C#常用三种命名方法
  1.匈牙利命名法(X)
  标识符的名字以一个或多个小写字母开头作为前缀;前缀之后的是首字母的一个单词或多个单词组合,该单词要指明变量的用途。
  基本原则是:变量名=属性+类型+对象描述,其中每一对象的名称都要求有明确含义,可以取对象名字全称或名字的一部分。
  如:表单的名称为form,那么在匈牙利命名法中可以简写为frm,则当表单变量名称为Switchboard时,变量全称应该为 frmSwitchboard。
  2.骆驼命名法(L)
  混合大小写字母来构成变量和函数的名字。
  如:printEmployeePaychecks(),函数名中的每一个逻辑断点都有一个大写字母来标记。
  3.帕斯卡(Pascal)命名法(P)
  与骆驼命名法类似。只不过骆驼命名法是首字母小写,帕斯卡命名法是首字母大写。
  如:public void DisplayInfo(); string UserName。
  4.三种命名法比较
  MyData 就是一个帕斯卡命名的示例
  myData是一个骆驼命名法,它第一个单词的第一个字母小写,后面的单词首字母大写,看起来像一个骆驼
  iMyData是一个匈牙利命名法,它的小写的i说明了它的型态,后面的和帕斯卡命名相同,指示了该变量的用途。
  5.使用说明
  在C#中以采用骆驼命名法和帕斯卡(Pascal)命名法居多。在下面的命名规范中需标识所采用的命名法。
  (2)代码规范
  1.解决方案命名
  项目名称(P) 如:Wisd
  2.工程命名
  公司名称(P)+"."+项目名(P)+模块名(P)
  如:WISD.WisdServer
  3.类命名
  都必须以名词或名词短语命名,体现类的作用。(P)
  如:TextManagemet
  4.文件夹命名
  文件夹命名一般采用英文,长度一般不超过20个字符,命名采用小写字母。(L)
  如:images(存放图形文件),flash(存放Flash文件),scripts(存放Javascript脚本)
  5.文件命名
  统一用小写的英文字母,数字和下划线的组合。(L)
  如:logo_police.gif
  (3)数据类型规范
  1.数据类型命名
  数据类型缩写+变量用途(X)
  2.附表说明
  数据类型 数据类型简写 标准命名举例 Array arr arrShoppingList Boolean                         bln blnIsPostBack Byte                           byt bytPixelValue Char                            chr chrDelimiter DateTime                       dtm dtmStartDate Decimal dec decAverageHeight Double                           dbl dblSizeofUniverse Integer         int intRowCounter Long                              lng lngBillGatesIncome Object           obj                  objReturnValue Short shr shrAverage Single sng sngMaximum String str strFirstName (4)控件规范
  1.控件命名
  控件类型缩写+变量用途(X)
  2.附表说明 控件类型 控件类型缩写 标准命名举例 Animated button ani aniMailBox Button btn Check box chk chkReadOnly ColorDialog clrdlg Combobox,drop-down list box cbo cboEnglish Communications com comFax ContextMenu ctxmnu Control(used within procedures when the specific type is unknown) ctr ctrCurrent CrystalReportViewer crvw Data dat datBiblio Data grid dgd dgdTitles Data list dbl dblPublisher Data repeater drp drpLocation Data-bound combo box dbcbo dbcboLanguage Data-bound grid dbgrd dbgrdQueryResult Data-bound list box dblst dblstJobType Datetime picker dtp dtpPublished Directory list box dir dirSource DomainUpDown dupd Drive list box drv drvTarget ErrorProvider err File list box fil filSource Flat scroll bar fsb fsbMove FontDialog fntdlg Form frm frmEntry Frame fra fraLanguage Gauge gau gauStatus Graph gra graRevenue Grid grd grdPrices GroupBox grp HelpProvider hlp Hierarchical flexgrid flex flexOrders HScroll bar hsb hsbVolume Image img imgIcon Image combo imgcbo imgcboProduct ImageList ils ilsAllIcons Label lbl lblHelpMessage Line lin linVertical LinkLabel lnk 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 MonthCalendar mcl MS Chart ch chSalesbyRegion MS Flex grid msg msgClients MS Tab mst mstFirst NotifyIcon nti NumericUpDown nupd OLE container ole oleWorksheet OpenFileDialog ofdlg PageSetUpDialog psdlg Picture box pic picVGA Picture clip clp clpToolbar PrintDocument prndoc PrintPreviewControl ppctl PrintPreviewDialog ppdlg ProgressBar prg prgLoadFile RadioButton rbtn Remote Data rd rdTitles RichTextBox rtf rtfReport SaveFileDialog sfdlg Shape shp shpCircle Slider sld sldScale Spin spn spnPages Splitter spt StatusBar sta staDateTime SysInfo sys sysMonitor TabContrl tab TabStrip tab tabOptions Text box txt txtLastName Timer tmr tmrAlarm Toolbar tlb tlbActions TrackBar trb TreeView tre treOrganization UpDown upd updDirection VScroll bar vsb vsbRate
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics