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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this