Sponsored By

Sign in to follow this  
iccaros

Enum C#

Recommended Posts

say I have an enum declared like so

enum lookup {a=1,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}

now I have an user enter a string (say a)

so

string mystring = a;

how do I take string a and get the value from the enum lookup

I've tried

int Iplace = (int)(lookup)mystring;

but that fails

if I change it to a char then It passes the value of the char not the char.

Share this post


Link to post
Share on other sites

Something like

int n = (int)Enum.parse(typeof(lookup), mystring);

?

Edited by jcl

Share this post


Link to post
Share on other sites

Thank you, Thank you, Thank you..

I tried that before severl times but was missing the ","

between (lookup) and mystring

so it keeped telling me I had an invalud overload of system.type which ment nothing to me, except I was wrong..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this