By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,467 Members | 1,520 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,467 IT Pros & Developers. It's quick & easy.

can I create an enum dynamically in the code?

P: n/a
Can I create an enum dynamically in the code, e.g. data base driven?

Thanks!
Ryan
Apr 4 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Would it be better to just use integer or char instead?

Afterall, the enum's effective value would be something of the sort.

"Ryan Liu" <ad********@online.sh.cn> glsD:OJ**************@TK2MSFTNGP14.phx.g bl...
Can I create an enum dynamically in the code, e.g. data base driven?

Thanks!
Ryan

Apr 4 '06 #2

P: n/a
Hi,

And use it how?

the only reason of the enum is to gives meanful names to values, just use
the values from the DB
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Ryan Liu" <ad********@online.sh.cn> wrote in message
news:OJ**************@TK2MSFTNGP14.phx.gbl...
Can I create an enum dynamically in the code, e.g. data base driven?

Thanks!
Ryan

Apr 4 '06 #3

P: n/a
On Tue, 04 Apr 2006 16:21:53 +0800, Ryan Liu Woke up an had these words of
wisdom to grace the world.:
Can I create an enum dynamically in the code, e.g. data base driven?

Thanks!
Ryan


How about EnumBuilder in system.Reflection.Emit ?

Apr 9 '06 #4

P: n/a
Can I create an enum dynamically in the code ...


enum My_enm : int
{
First_value,
Second_value
}

int l_enm_val = 7;
Enum l_new_enm_ins;
Type l_enm_typ;
Object l_enm_obj

l_enm_typ = typeof( My_enm );

l_new_enm_ins = ( Enum ) Activator.CreateInstance(l_enm_typ);

l_new_enu_ins = ( Enum ) Activator.CreateInstance(l_enm_typ, l_num_value );

l_enm_obj = ( My_enm ) Enum.ToObject( l_enm_typ, l_enm_val );

Hope this helps.

Shawnk
Jun 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.