Larsenal
Larsenal

Reputation: 51146

Converting enum tostring of underlying type in VB.Net (Option Strict On)

I'd like to get a string representation of the underlying type of the enum.

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

Upvotes: 2

Views: 1355

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062502

In C# terms; you could assume int:

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

or if you don't want the assumption:

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

Upvotes: 2

Related Questions