控件命名规则
控件名 | 简写 | 控件名 | 简写 |
Label | lbl | TextBox | txt |
Button | btn | LinkButton | lnkbtn |
ImageButton | imgbtn | DropDownList | ddl |
ListBox | lst | DataGrid | dg |
DataList | dl | CheckBox | chk |
CheckBoxList | chkls | RadioButton | rdo |
RadioButtonList | rdolt | Image | img |
Panel | pnl | Calende | cld |
AdRotator | ar | Table | tbl |
RequiredFieldValidator | rfv | CompareValidator | cv |
RangeValidator | rv | RegularExpressionValidator | rev |
ValidatorSummary | vs | CrystalReportViewer | rptvew |
匈牙利命名法
匈牙利命名法是一名匈牙利程序员发明的,而且他在微软工作了多年。此命名法就是通过
微软的各种产品和文档传出来的。多数有经验的程序员,不管他们用的是哪门儿语言,都或
多或少在使用它。
这种命名法的基本原则是:
变量名=属性+类型+对象描述
即一个变量名是由三部分信息组成,这样,程序员很容易理解变量的类型、用途,而且便于
记忆。
下边是一些推荐使用的规则例子,你可以挑选使用,也可以根据个人喜好作些修改再用之。
⑴属性部分:
全局变量: g_
常量 : c_
类成员变量: m_
⑵类型部分:
指针: p
句柄: h
布尔型: b
浮点型: f
无符号: u
⑶描述部分:
初始化: Init
临时变量: Tmp
目的对象: Dst
源对象: Src
窗口: Wnd
下边举例说明:
hwnd: h 表示句柄,wnd 表示窗口,合起来为“窗口句柄”。
m_bFlag: m 表示成员变量,b 表示布尔,合起来为:“某个类的成员变量,布尔型,
是一个状态标志”。
语句命名规则
1每行一个语句
每行最多包含一个语句。如
a++; //推荐
b--; //推荐
a++; b--; //不推荐
2 复合语句
复合语句是指包含"父语句{子语句;子语句;}"的语句,使用复合语句应遵循以下几点
1 子语句要缩进。
2 左花括号“{” 在复合语句父语句的下一行并与之对齐,单独成行。
3 即使只有一条子语句要不要省略花括号“ {}”。 如
while (d + = s++)
{
n++;
}
3 return 语句
return 语句中不使用括号,除非它能使返回值更加清晰。如
return;
return myDisk.size();
return (size ? size : defaultSize);
4 if、 if-else、if else-if 语句
if、 if-else、if else-if 语句使用格式
if (condition)
{
statements;
}
if (condition)
{
statements;
}
else
{
statements;
}
if (condition)
{
statements;
}
else if (condition)
{
statements;
}
else
{
statements;
}
5 for、foreach 语句
for 语句使用格式
for (initialization; condition; update)
{
statements;
}
空的 for 语句(所有的操作都在 initialization、condition 或 update 中实现)使用格式
for (initialization; condition; update); // update user id
foreach 语句使用格式
foreach (object obj in array)
{
statements;
}
注意 1 在循环过程中不要修改循环计数器。
2 对每个空循环体给出确认性注释。
6 while 语句
while 语句使用格式
while (condition)
{
statements;
}
空的 while 语句使用格式
while (condition);
7 do - while 语句
do - while 语句使用格式
do
{
statements;
} while (condition);
8. switch - case 语句
switch - case 语句使用格式
switch (condition)
{
case 1:
statements;
break;
case 2:
statements;
break;
default:
statements;
break;
}
注意:
1、语句 switch 中的每个 case 各占一行。
2、语句 switch 中的 case 按字母顺序排列。
3、为所有 switch 语句提供 default 分支。
4、所有的非空 case 语句必须用 break; 语句结束。
9. try - catch 语句
try - catch 语句使用格式
try
{
statements;
}
catch (ExceptionClass e)
{
statements;
}
finally
{
statements;
}
10 using 块语句
using 块语句使用格式
using (object)
{
statements;
}
11 goto 语句
goto 语句使用格式
goto Label1:
statements;
Lable1:
statements;