# 何时使用枚举 (Visual Basic)When to Use an Enumeration (Visual Basic)

## 何时使用枚举When to Use an Enumeration

• 减少由转置或错误错误导致的错误。Reduces errors caused by transposing or mistyping numbers.

• 以后可以轻松地更改值。Makes it easy to change values in the future.

• 使代码更易于阅读，这意味着错误会在其中蔓延。Makes code easier to read, which means it is less likely that errors will creep into it.

• 确保向前兼容性。Ensures forward compatibility. 对于枚举，如果将来有人更改了与成员名称相对应的值，你的代码将不太可能失败。With enumerations, your code is less likely to fail if in the future someone changes the values corresponding to the member names.

## 预定义枚举Predefined Enumerations

Visual Basic 提供了许多预定义的枚举，如 FirstDayOfWeekMsgBoxResult，以便于代码。Visual Basic provides a number of predefined enumerations, such as FirstDayOfWeek and MsgBoxResult, to facilitate your code. 有关这些变量的列表，请参阅常量和枚举For a list of these see Constants and Enumerations.