如何:引用枚举成员 (Visual Basic)How to: Refer to an Enumeration Member (Visual Basic)

枚举提供了一种简便的方法来处理相关常量集,并将常量值与名称相关联。Enumerations provide a convenient way to work with sets of related constants and to associate constant values with names. 例如,可以为一组与星期几相关联的整数常量声明一个枚举,然后在代码中使用星期几的名称而不是整数值。For example, you can declare an enumeration for a set of integer constants associated with the days of the week, and then use the names of the days rather than their integer values in your code.

您可以避免对 Imports 语句使用完全限定的名称。You can avoid using fully qualified names with the Imports statement. 有关详细信息,请参阅枚举和名称限定For more information, see Enumerations and Name Qualification.

引用枚举成员To refer to an enumeration member

  • 用枚举限定成员名称。Qualify the member name with the enumeration. 例如,下面的示例将 FirstDayOfWeek 枚举的 Saturday 成员分配给变量 DayValueFor example, the following example assigns the Saturday member of the FirstDayOfWeek enumeration to the variable DayValue.

    DayValue = FirstDayOfWeek.Saturday
    

另请参阅See also