Saturday, January 21, 2006
by Nik Kalyani
Saturday, January 21, 2006 12:54:51 PM (Pacific Standard Time, UTC-08:00)

Frequently, you will have a situation where you store the string representation of an enumerated value in a file or database, and when it is retrieved you have to re-assign it to a variable that is of the enumerated type. You can do this as follows:

public enum MyEnumeratedType
{
     Foo = 0, Bar = 1
}

MyEnumeratedType enumVariable = (MyEnumeratedType) Enum.Parse(typeof(MyEnumeratedType), “Bar”, true);

With all due respect to Anders, this is NUTS!!! I wish there was a simpler way…

#    Comments [0] - Trackback    

Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, i, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
RSS feed
Search and Links
Bling

View Nik Kalyani's profile on LinkedIn

Contact me: nik*kalyani.com (replace "*")

TechBubble
www.flickr.com
This is a Flickr badge showing public photos from techbubble. Make your own badge here.
Statistics
Total Posts: 214
This Year: 32
This Month: 0
This Week: 0
Comments: 238
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008
Nik Kalyani
Sign In
All Content © 2008, Nik Kalyani