枚举提供了一种使用相关常量集以及将常量值与名称关联起来的便捷方法。 若要循环访问枚举,可以使用该方法将其移动到数组 GetValues 中。 还可以使用 For...Each
语句循环访问枚举,使用 GetNames 或 GetValues 方法提取字符串或数值。
循环访问枚举
声明数组并在传递数组之前使用 GetValues 方法将枚举转换到数组,就像传递任何其他变量一样。 下面的示例显示在循环访问枚举时枚举 FirstDayOfWeek 的每个成员。
Dim items As Array items = System.Enum.GetValues(GetType(FirstDayOfWeek)) Dim item As String For Each item In items MsgBox(item) Next