Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert from String to Enum return not valid cast in WPF [duplicate]

Tags:

c#

.net

enums

wpf

I trying to convert from WPF combobox selected value to enumurator it return not valid cast in the runtime otherwise the string and the enum name is matched my code is

Siren.PfundMemberWebServices.Emirates EM = (Siren.PfundMemberWebServices.Emirates)cmbemirate.SelectedValue
like image 790
Badr Hussien Avatar asked Jan 20 '14 12:01

Badr Hussien


1 Answers

To convert a string to an enum you need to use Enum.Parse

Siren.PfundMemberWebServices.Emirates EM = (Siren.PfundMemberWebServices.Emirates)Enum.Parse(typeof(Siren.PfundMemberWebServices.Emirates), cmbemirate.SelectedValue);
like image 113
Sean Avatar answered Sep 30 '22 09:09

Sean