如何在代码中列出枚举的成员?我有以下枚举:
Public Enum TestEnum As int32 First = 0 Second = 2 Third = 4 Fourth = 6 End Enum
我尝试通过以下代码列出TestEnum的所有成员,但失败:
Public Class Form1 Private Sub Button1_Click(sender As System.Object,e As System.EventArgs) Handles Button1.Click Dim Enum1 As TestEnum Dim Members() As String Members = System.Enum.GetNames(CType(Enum1,System.Enum)) End Sub End Class
所以我的问题是:如何列出枚举成员?
更新:解决方案是:
Public Class Form1 Private Sub Button1_Click(sender As System.Object,e As System.EventArgs) Handles Button1.Click Dim Members() As String Members = System.Enum.GetNames(GetType(TestEnum)) MessageBox.Show(Join(Members,Chr(13) & Chr(10))) End Sub End Class