Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
785 views
in Technique[技术] by (71.8m points)

.net - typeof(System.Enum).IsClass == false

Founded that:

typeof(System.Enum).IsClass == false

It's become strange that System.Enum has also .IsValueType == false, but Reflector shows that it is really just an abstract class.

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's an issue with .Net 1.1 and 2.0. I haven't checked it in 3.0

From MSDN User David Bernstein

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...