C#命名约定[转]
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
|
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
|
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 |
变量
变量的作用域及前缀
前缀 |
说明 |
举例 |
P |
全局变量 |
pstrName |
St |
静态变量 |
ststrName |
M |
模块或者窗体的局部变量 |
MstrName |
A |
数组 |
AintCount[] |
变量数据类型的前缀
C#数据类型
|
类库数据类型
|
标准命名举例
|
Sbyte
|
System.sbyte
|
sbte
|
Short
|
System.Int16
|
sht
|
Int
|
System.Int32
|
int
|
Long
|
System.Int64
|
lng
|
Byte
|
System.Byte
|
bte
|
Ushot
|
System.Uint16
|
usht
|
Uint
|
System.Uint32
|
uint
|
Ulong
|
System.Uint64
|
ulng
|
Float
|
System.Single
|
flt
|
Double
|
System.Double
|
dbl
|
Decimal
|
System.Decimal
|
dcl
|
Bool
|
System.Boolean
|
bol
|
Char
|
System.Char
|
chr
|
Object
|
System.Object
|
obj
|
String
|
System.String
|
str
|
|
System.DateTime
|
dte
|
IntPtr
|
System.Intpre
|
intptr
|
常量定义
常量=作用域+ c+数据类型+变量名
类对象定义
类实例=作用域+cls+变量名
类对象=C+名称
结构对象定义
结构对象实例=作用域+struc+变量名
结构对象=S+名称
命名空间定义
以层为前缀进行命名
接口定义
以大写I为前缀
窗体的命名规则
窗体名=frm+窗体名(名词+动词)
注意:保存的文件明和窗体名相同。
枚举定义规则
以Enum为前缀
事件命名规则
事件控制器要带有EventHandler后缀
使用sender和e命名两个参数
事件参数类要带有EventArgs后缀
考虑使用动词命名事件
对于有“之前”或“之后”概念的事件,要使用现在时或过去时命名
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器