开发者

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 re开发者_运维问答turns it as type object. How do I convert this object to my enum?

My framework is silverlight on windows-phone-7


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.


Have you tried this??

YourEnum abc = (YourEnum) Enum.Parse(typeof(YourEnum), yourObject.ToString());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜