如何通过使用循环将值作为逗号分隔的值传递来获取枚举字符串值 [英] How to get enum string values by passing values as comma separated value with using loop

查看:120
本文介绍了如何通过使用循环将值作为逗号分隔的值传递来获取枚举字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有预定义的数据列表,我不想将所有这些数据原样存储在数据库中,也不想为这些数据创建单独的表.因此,我使用了枚举器,并且仅将枚举器值(例如"1、3、4、5、6")保存在数据库中.现在,我将记录取为"1、3、4、5、6",并且必须在用户界面中检查这些值.如何在不使用循环的情况下通过将这些ID作为逗号分隔的值传递而从Enum中获取字符串值,可能是使用LINQ.


在此先感谢

Hi,

I have list of data which are predefined, I don''t want to store all those data in the database as it is and also I don''t want to have separate table for those data. So I have used Enumerators and saved only the enumerators values like ''1,3,4,5,6'' in the database. Now I fetch the record as ''1,3,4,5,6'' and I have to check those values in the user interface. How do I get the string values from Enum by passing these IDs as comma separated value without using loop may be by using LINQ.


Thanks in advance

推荐答案

将其投射为枚举类型:
Cast it to the enum type:
MyEnum me = (MyEnum) myInteger;

然后只需使用ToString重写即可获取枚举值名称:

Then just use the ToString override to get the enum value name:

string s = me.ToString();


这篇关于如何通过使用循环将值作为逗号分隔的值传递来获取枚举字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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