5.15 集合
集合是一组组合在一起的类似的类型化对象,如哈希表、查询、堆栈、字典和列表,集合的命名 建议用复数。
5.16 措词
避免使用与常用的 .NET 框架命名空间重复的类名称。例如,不要将以下任何名称用作类名称: System、Collections、Forms 或 UI。有关 .NET 框架命名空间的列表,请参阅类库。 另外,避免使用和以下关键字冲突的标识符。 AddHandler AddressOf Alias As Assembly Auto ByRef Byte ByVal Catch CBool CByte CDec CDbl Char CLng CObj Const CStr CType Date Default Delegate Dim Each Else ElseIf Erase Error Event False Finalize Finally Friend Function Get Handles If Implements Inherits Integer Interface Lib Like Long Mod Module MustInherit MyClass Namespace
New
Nothing NotInheritable NotOverridable Option
Optional
Or Overrides ParamArray Preserve Protected Public RaiseEvent Region REM RemoveHandler Select Set Shadows Single
Static
Step Structure Sub SyncLock To True Try Until
volatile
When WithEvents WriteOnly Xor instanceof package
var
And Ansi Base Boolean Call Case Cchar CDate Cint Class Cshort CSng Decimal Declare Do Double End Enum
Exit ExternalSource Float For GetType Goto Imports In Is Let Loop
Me
MustOverride MyBase Next
Not Object On
Overloads Overridable Private Property ReadOnly ReDim Resume Return Shared Short Stop String Then Throw TypeOf Unicode While With Eval extends
26
第六章 语句
6.1
每行一个语句
每行最多包含一个语句。如 a++; //推荐 b--; //推荐
a++; b--; //不推荐
6.2 复合语句
复合语句是指包含\父语句{子语句;子语句;}\的语句,使用复合语句应遵循以下几点 1 子语句要缩进。
2 左花括号“{” 在复合语句父语句的下一行并与之对齐,单独成行。 3 即使只有一条子语句要不要省略花括号“ {}”。 如
while (d + = s++) { n++; }
6.3 return 语句
return语句中不使用括号,除非它能使返回值更加清晰。如
return;
return myDisk.size();
return (size ? size : defaultSize);
6.4 if、 if-else、if else-if 语句
if、 if-else、if else-if 语句使用格式
if (condition) {
statements; }
if (condition) {
statements; } else {
statements; }
27
if (condition) {
statements; }
else if (condition) {
statements; } else {
statements; }
6.4 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.5 while 语句
while 语句使用格式
while (condition) {
statements; }
28
空的 while 语句使用格式
while (condition);
6.7. do - while 语句
do - while 语句使用格式 do {
statements;
} while (condition);
6.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; 语句结束。
6.9. try - catch 语句
try - catch 语句使用格式 try {
statements; }
catch (ExceptionClass e)
29
{
statements; } finally {
statements; }
6.10. using 块语句
using 块语句使用格式 using (object) {
statements; }
6.11. goto 语句
goto 语句使用格式 goto Label1: statements; Lable1: statements;
30