Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert object to enum C#

I have binded a list of enum to a combobox. Now I want to get the SelectedItem return the enum, which currently returns it as type object. How do I convert this object to my enum?

My framework is silverlight on windows-phone-7

like image 674
Shawn Mclean Avatar asked May 24 '10 07:05

Shawn Mclean


2 Answers

Cast it directly:

MyEnum selected = (MyEnum)cboCombo.SelectedItem;

Note that you can't use the as cast in this case since an Enum is a value type.

like image 52
Jon Seigel Avatar answered Sep 30 '22 10:09

Jon Seigel


Have you tried this??

YourEnum abc = (YourEnum) Enum.Parse(typeof(YourEnum), yourObject.ToString());
like image 39
viky Avatar answered Sep 30 '22 11:09

viky