【发布时间】:2014-11-18 09:57:01
【问题描述】:
我有两个枚举和一个通用方法。泛型类型 T 可以是枚举之一。
public enum myEnumA
{
a,
b
}
public enum myEnumB
{
c,
d
}
public void myMethod<T>()
{
if (typeof(T) is myEnumA)
{
//do something
}
else if (typeof (T) is myEnumB)
{
//do something else
}
}
关于 if 检查,编译器告诉我“给定的表达式永远不是提供的类型”。 有没有办法在运行时判断它是哪个确切的枚举?
【问题讨论】:
-
欢迎来到 StackOverflow!请参阅"Should questions include “tags” in their titles?",其中的共识是“不,他们不应该”。