16,555
社区成员
发帖
与我相关
我的任务
分享
Enum a1
str1 = 11
str2 = 11
End Enum
Enum a2
str1 = 21
str2 = 22
End Enum
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim a1 As a1
Dim a2 As a2
Dim strTemp As String = ""
Dim strResult As String = ""
strResult = GetStr(a1)
End Sub
Function GetStr(ByVal v_str As Object) As String
Dim strResult As String = ""
'如何判断v_str是属于a1还是a2或者都不属于
Dim objType As Type
objType = v_str.GetType()
'枚举需要判断
If objType.IsEnum = True Then
'提取枚举类型名即可判断
strResult = objType.Name
End If
End Function