如何:确定与枚举值关联的字符串 (Visual Basic)
GetValues 和 GetNames 方法支持确定与枚举成员关联的字符串和值。
确定与枚举关联的字符串
使用 GetNames 方法检索与枚举成员关联的字符串。 此示例声明一个枚举
flavorEnum
,然后使用 GetNames 方法显示与每个成员关联的字符串。Public Enum flavorEnum salty sweet sour bitter End Enum Private Sub TestMethod() MsgBox("The strings in the flavorEnum are:") Dim i As String For Each i In [Enum].GetNames(GetType(flavorEnum)) MsgBox(i) Next End Sub
另请参阅
反馈
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:提交和查看相关反馈