Skip to content

Commit 331f2b7

Browse files
committed
enum
1 parent 1b6379a commit 331f2b7

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎CodeComplete/ThePowerofVariableNames.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,32 @@
164164
root[1] = ( -b - descriminant )/( 2*a )
165165
```
166166
本质上上面两代码完全相同,但是第二段使用了具有描述性的变量命名(discriminant,判别式)
167+
168+
### Naming Enumerated Types 为枚举类型命名
169+
在使用枚举类型的时候,可以通过使用组前缀,如Color_,Planet_或者Month_来明确表示该类型的成员都属于一个组。
170+
```
171+
Visual Basic
172+
Public Enum Color
173+
Color_Red
174+
Color_Green
175+
Color_Blue
176+
End Enum
177+
178+
Public Enum Planet
179+
Planet_Earth
180+
Planet_Mars
181+
Planet_Venus
182+
End Enum
183+
184+
Public Enum Month
185+
Month_January
186+
Month_Februay
187+
...
188+
Month_December
189+
End Enum
190+
```
191+
对于枚举类型的两种看法:
192+
用户定义类型,因此枚举名字的格式应该与其他用户定义的类型如类相同。
193+
枚举是一种类型,同时也是常量,因此名字的格式与常量相同。
194+
195+

0 commit comments

Comments
 (0)