Rick van den Bosch - Blog

... on .NET, software architecture, software development and whatnot

Recent Posts

Tags

News

  • Live space

    Photo blog

    Follow me at twitter

    Rick  van den Bosch

    LinkedIn profile

    Add to Technorati Favorites

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

Community

Email Notifications

Blogs I read

Interesting links

Archives

Converting string to enumeration value

Questa posted a very usefull piece of code...
It's possible to convert a string representation of an enum back to an enum!

  private enum MyEnumeration
  {
      FooBar,
      Foo,
      Bar
  }

  ...

  MyEnum foo = MyEnum.Foo;
  string foobar = foo.ToString();
  MyEnum bar = (MyEnum)Enum.Parse(typeof(MyEnum), foobar);

At the end of this code, the variable 'bar' has the MyEnum value 'Foo', just the way it's supposed to be...

Comments

Puneet said:

Really helpful.

# January 16, 2008 10:23 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)