Posted By

elugardo on 08/28/07


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

umang_nine
jasonseney
kat


Enum to string and string to enum


 / Published in: C#
 

Examples of converting from a string to an enum value and back

  1. //convert enum to string. mode is an Enum of type PageModeEnum.
  2. //Enum.GetName returns the name the mode is set to
  3. Enum.GetName( typeof(PageModeEnum), mode)
  4.  
  5. //convert a string to an emum.
  6. //buttonState is the string
  7. //ButtonState is the enum type
  8. (ButtonState)Enum.Parse(typeof(ButtonState);, buttonState, true);

Report this snippet  

You need to login to post a comment.