在VB.NET中将字符串解析为枚举值 [英] Parse a string to an Enum value in VB.NET
本文介绍了在VB.NET中将字符串解析为枚举值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例我有这个枚举:
公开枚举性别
未定义
男性
女性
结束枚举
如何将字符串Male转换为性别
枚举的 code> value?
解决方案
Dim val = DirectCast([Enum])。 Parse(GetType(Gender),Male),Gender)
How can I parse a string in VB.NET to enum value?
Example I have this enum:
Public Enum Gender
NotDefined
Male
Female
End Enum
how can I convert a string "Male" to the Gender
enum's Male
value?
解决方案
Dim val = DirectCast([Enum].Parse(GetType(Gender), "Male"), Gender)
这篇关于在VB.NET中将字符串解析为枚举值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文