How to Convert a string to an enum in C#?

Answer

StatusEnumMyStatus=(StatusEnum)Enum.Parse(typeof(StatusEnum),"Active",true);

I tend to simplify this with:

publicstatic T ParseEnum<T>(string value ){return(T)Enum.Parse(typeof( T ), value,true);}

Then I can do:

StatusEnumMyStatus=EnumUtil.ParseEnum<StatusEnum>("Active");

All string Questions

Ask your interview questions on string

Write Your comment or Questions if you want the answers on string from string Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---