c# - How to set a string to an enum variable? -



c# - How to set a string to an enum variable? -

possible duplicate: cast string enum enum attribute

i have enum this:

public enum iddfiltercomparetocurrent { [stringvalue("ignore")] ignore, [stringvalue("pre-post")] prepost, [stringvalue("custom")] custom }

i have domainupdown controls filled same values of enum defined, exept because enum not take - character, had utilize attributes match them domainupdown contents.

now question how can insert selected item of domainupdown variable of enum type?

something like:

private iddfiltercomparetocurrent myenum = enum.parse(typeof(iddfiltercomparetocurrent), domainupdown1.selecteditem.tostring());

i error:

cannot implicitly convert type 'object' 'filtering.iddfiltercomparetocurrent'. explicit conversion exists (are missing cast?)

do this:

private iddfiltercomparetocurrent myenum = (iddfiltercomparetocurrent )enum.parse(typeof(iddfiltercomparetocurrent ),domainupdown1.selecteditem.tostring());

enum.parse returns object, need cast it.

c# .net string enums

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -