假设我有以下枚举值
enum Language
{
CSharp= 0,
Java = 1,
VB = 2
}
Run Code Online (Sandbox Code Playgroud)
我想将它们转换为值列表(即) { CSharp,Java,VB}.
如何将它们转换为值列表?
public enum VehicleData
{
Dodge = 15001,
BMW = 15002,
Toyota = 15003
}
Run Code Online (Sandbox Code Playgroud)
我想在字符串数组中得到值15001,15002,15003,如下所示:
string[] arr = { "15001", "15002", "15003" };
Run Code Online (Sandbox Code Playgroud)
我试过下面的命令,但这给了我一些名字而不是值.
string[] aaa = (string[]) Enum.GetNames(typeof(VehicleData));
Run Code Online (Sandbox Code Playgroud)
我也尝试过,string[] aaa = (string[]) Enum.GetValues(typeof(VehicleData));
但也没有用.
有什么建议?
我有大约30个不同的标记枚举,我想将其放入数组中以进行索引和快速访问.我还要声明,我没有1个包含30个值的枚举,但我有30个具有不同数值的枚举.
目标是将它们添加到指定索引处的数组中.这样我就可以编写一个函数,我可以在其中传递数组索引来设置枚举的粒度值.
更新:这是我想要做的一个例子.
枚举main(enum1 = 0,enum2 = 1,enumn = n-1) - 这个索引与相关枚举的索引相匹配
[flag] enum1(value1 = 0,value2 = 1,value3 = 2,value4 = 4 ......)
[flag] enum2("")
[flag] enum2("")
因为我使用的是可标记的枚举,所以我有一个如下的类
public static class CEnumWorker
{
public static enum1 myEnum1 = enum1.value1;
public static enum2 myEnum2 = enum2.value1;
public static enumN myEnumN = enumN.value1;
//I would then have functions that set the flags on the enums. I would like to access the enums through an array or other method so that I do …
Run Code Online (Sandbox Code Playgroud)