Enum to string and string to enum


/ Published in: C#
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.