Read this article in your language IT | EN | DE | ES
I had a need to take a string value and get it’s equivalent Enum type back. This is how you can do that in VB.Net.
Public Enum PackageTypes
Subscription = 1
Sponsorship = 2
End Enum
Dim EnumValue As PackageTypes
EnumValue = CType([Enum].Parse(GetType(PackageTypes), "Subscription", True), PackageTypes)
What if it doesn’t exist? You want to check to see if it does first.
You can check to see like this:
If [Enum].IsDefined(GetType(PackageTypes), "Subscription") Then
'Run previous code snippet here
EnumValue = CType([Enum].Parse(GetType(PackageTypes), "Subscription", True), PackageTypes)
End IF
9a304423-2218-415c-b17d-539ad92c2f90|1|5.0
Code Snippets, VB.NET, Programming
code snippets, vb.net, programming