typeof运算(System.Enum).IsClass ==假 [英] typeof(System.Enum).IsClass == false

查看:118
本文介绍了typeof运算(System.Enum).IsClass ==假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

成立的:

typeof(System.Enum).IsClass == false

这已经成为奇怪的是, System.Enum .IsValueType ==假,但反射表明,它是真的只是一个抽象类

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 和<$铸造枚举值/ C C> 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用户大卫·伯恩斯坦

在System.Enum类型的IsClass属性,则返回假,即使System.Enum,从System.ValueType和typeof运算(System.ValueType).IsClass返回真继承(预期) 。与此同时,typeof运算(System.Enum).IsValueType如预期返回假。这种观察到的行为似乎违背了明确的文档上面,规定:   这个属性返回true再presenting枚举和值类型类型的实例。我发现这是事实在这两个框架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 ==假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆