string value of enum

R

RP

Hi all, I was wondering if there was a way to return the string value of an
enumeration. Example:

Public Enum MyStatus
NA
YES
NO
End Enum

Dim a as MyStatus = MyStatus.YES
response.write(Cstr(a)) ' returns 0

Instead I need "YES"

TIA,
PR
 
R

RP

I tried the reverse and it did not work:

Dim strvalue as string = "YES"
Dim b as MyStatus = CType(strvalue, MyStatus)

any ideas?
 
J

Jon Skeet [C# MVP]

RP said:
I tried the reverse and it did not work:

Dim strvalue as string = "YES"
Dim b as MyStatus = CType(strvalue, MyStatus)

Look at Enum.Parse.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

system.enum.getvalues 5
Reflection, Enums and their values? 3
about enum 3
enum problems 5
report summary 2
Enum Extentions 7
Merge Info From Two Enums 1
retrieving the XmlEnumAttribute values for an Enum 1

Top