有没有办法使用C ++ / CLI管理的枚举作为数组下标?

时间:2009-02-04 21:22:55

标签: c++-cli

我有一个枚举声明为

enum class AccessLevel : int
{
    ReadOnly = 0,
    Excluded = 1,
    ReadWrite = 2,
};

和一个声明为

的数组
static array<String^>^ _accessMap = gcnew array<String^> { "R", "X", "W" };

我想做这样的事情:

AccessLevel^ access = access::ReadOnly;
String^ foo = _accessMap[access];

1 个答案:

答案 0 :(得分:2)

public enum struct AccessLevel
{
        ReadOnly = 0,
        Excluded = 1,
        ReadWrite = 2,
};

AccessLevel access = access::ReadOnly;

您可能需要转换为int

String^ foo = _accessMap[(int)access];