获取一个泛型的枚举的整数值 [英] Get the Integer value of an enumeration which is a generic
本文介绍了获取一个泛型的枚举的整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是基本情况。
Public Class MyEnumClass(of T)
Public MyValue as T
End Class
这是对实际类的大量过度简化,但基本上我知道T是枚举(如果不是那么会有很多其他的问题,而且是程序员发出的逻辑错误)
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)
基本上我想要获得MyValue的底层整数值
Basically I want to get the underlying integer value of MyValue.
使用Cint或Ctype不起作用。
Using Cint or Ctype, does not work.
推荐答案
我将使用一个很酷的反思代码,但只是一个简单的 Convert.ToInt32
工作得很好...原谅我的VB我是一个C#人
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
Public Function GetEnumInt(Of T)(enumVal As T) As Integer
Return Convert.ToInt32(enumVal)
End Function
这篇关于获取一个泛型的枚举的整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文