如何动态创建枚举? [英] How to create enum dynamically?

查看:176
本文介绍了如何动态创建枚举?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据数据库中的表创建一个枚举。

I need to create an enum based on a table from the database.

数据库表MyColors:id / title / value
1 / Red / 1
2 /绿色/ 4

DB table MyColors: id/title/value 1/Red/1 2/Green/4

动态创建

enum MyColors {
    Red=1,
    Green=4;
}


推荐答案

您可以动态创建源代码通过从数据库中读取并简单地以有助于构建枚举的格式输出结果。但是,在运行时创建枚举是不切实际的。使用某种关联数组会更好。

You can dynamically create source code by reading from the database and simply outputting the results in a format conducive to building an enum. However, it is impractical to create an enum at run time. You would be better off with some kind of associative array.

这篇关于如何动态创建枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆