在VB.Net中转换底层类型的枚举tostring(Option Strict On)

时间:2009-01-30 20:42:58

标签: vb.net enums option-strict

我想获得枚举的基础类型的字符串表示。

    Dim target As System.ConsoleColor = ConsoleColor.Cyan
    Dim actual = 'What goes here?
    Dim expected = "11"

1 个答案:

答案 0 :(得分:2)

用C#术语;你可以假设int:

int val = (int) target;
string valString = val.ToString();

或者如果你不想要这个假设:

object val = Convert.ChangeType(target,
    Enum.GetUnderlyingType(typeof(ConsoleColor)));
string valString = val.ToString();