如何:引用枚举成员 (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. 例如,下面的示例将分配Saturday的成员FirstDayOfWeek给该变量的枚举DayValueFor example, the following example assigns the Saturday member of the FirstDayOfWeek enumeration to the variable DayValue.

    DayValue = FirstDayOfWeek.Saturday
    

请参阅See also