Skip to main content

Mark Wagner - Cogitation Blog

Go Search
Blog
SPDev
SharePoint
Governance
  

Welcome
Mark Wagner works for Microsoft as a Consultant working in the West Region.
My old blog
Mark Wagner - Cogitation Blog > Posts > Convert a string to an enumerated (enum) value.
Convert a string to an enumerated (enum) value.

Using the Enum.Parse method, you can easily convert a string value to an enumerated value.  Doing this requires the type of the enum and string value.  Adding the true argument will cause the case to be ignored.

Using the following enum for this example:

private enum Aircraft
{
   Beech,
   Cessna,
   Piper
}

You can easily convert the string to an enum value like this:

Aircraft air = (Aircraft) Enum.Parse(typeof(Aircraft), "Cessna", true);

Ideally you should wrap a try-catch around the Enum.Parse statement.

(Note: Re-post from my old blog.)

Comments

There are no comments yet for this post.
Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Today's Date *

Please enter today's date. This will help prevent blog spam. Thank you.
Attachments