typeof(System.Enum).IsClass == false [英] typeof(System.Enum).IsClass == false
问题描述
成立:
typeof(System.Enum).IsClass == false
System.Enum
也有 .IsValueType变得奇怪== false
,但Reflector显示它真的只是一个抽象类
。
It's become strange that System.Enum
has also .IsValueType == false
, but Reflector shows that it is really just an abstract class
.
System.Enum
是类似于 System.ValueType
的引用类型,并将枚举值转换为/ code> System.Enum 引用引用拳击/取消装箱。
System.Enum
is a reference type like a System.ValueType
and casting enumeration values to/from System.Enum
reference caused boxing/unboxing. No surprises here.
但是,的原因是什么类型
类不讲真相关于 System.Enum
性质?
没有任何异常的 System.Enum
类型的反射行为,使其看起来不像引用类型。
But what is a reason for Type
class not to tell truth about System.Enum
nature?
There is no anything extraordinary with the System.Enum
type's reflection behavior to make it looks like not a reference type.
推荐答案
.Net 1.1和2.0是一个问题。我没有在3.0中检查
It's an issue with .Net 1.1 and 2.0. I haven't checked it in 3.0
从MSDN用户 David Bernstein
System.Enum类型的IsClass属性返回false ,即使System.Enum继承自System.ValueType和typeof(System.ValueType).IsClass返回true(如预期)。同时,typeof(System.Enum).IsValueType返回false。这种观察的行为似乎与上述显式文档相矛盾:
该属性对于表示枚举和值类型的类型实例返回true。我发现在框架1.1和2.0中都是这样。
The IsClass property of the System.Enum type returns "false", even though "System.Enum" inherits from "System.ValueType" and "typeof(System.ValueType).IsClass" return "true" (as expected). At the same time, typeof(System.Enum).IsValueType returns "false" as expected. This observed behavior seems to contradict the explicit documentation above which stipulates: "This property returns true for Type instances representing Enum and ValueType." I found this to be the case in both frameworks 1.1 and 2.0.
这篇关于typeof(System.Enum).IsClass == false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!