views:

1225

answers:

3

Here is the basic situation.

Public Class MyEnumClass(of T)
   Public MyValue as T
End Class

This is vast oversimplification of the actual class, but basically I know that T is an enumeration (if it is not then there will be many other problems, and is a logical error made by the programmer)

Basically I want to get the underlying integer value of MyValue.

Using Cint or Ctype, does not work.

A: 

I tried this and it worked:

String.Format("{0:d}", MyValue)
Ross Goddard
Well that converts it into a *string* - I thought you wanted it as an integer?
Jon Skeet
A: 

I know you can do the following to get all the underlying values (I hope my VB syntax is correct... I've been working in C# mostly of late):

Dim intVal As Integer

For Each intVal In  [Enum].GetValues(GetType(T))
    //intValue is now the enum integer value
Next

That might at least get you started in the right direction.

Jason Down
+2  A: 

I was going to use a cool piece of reflection code but just a simple Convert.ToInt32 works great... Forgive my VB I'm a C# guy

Sub GetEnumInt(of T)(enumVal as T) as Int
    return Convert.ToInt32(enumVal)
EndSub
joshperry