gpt4 book ai didi

c# - 如果 System.Enum 是一个类,它怎么可能也是一个 ValueType?

转载 作者:太空宇宙 更新时间:2023-11-03 21:49:12 24 4
gpt4 key购买 nike

System.ValueType 是一个类,从它派生的所有内容都是值类型,因此不能是类,因为类是引用类型。

那么怎么可能将 System.Enum(继承 System.ValueType)定义为一个类?

最佳答案

.NET 中的一切都派生自 System.Object:

Both reference and value types are derived from the ultimate base class Object. In cases where it is necessary for a value type to behave like an object, a wrapper that makes the value type look like a reference object is allocated on the heap, and the value type's value is copied into it. The wrapper is marked so the system knows that it contains a value type. This process is known as boxing, and the reverse process is known as unboxing. Boxing and unboxing allow any type to be treated as an object.

http://msdn.microsoft.com/en-us/library/system.valuetype(v=vs.110).aspx

关于c# - 如果 System.Enum 是一个类,它怎么可能也是一个 ValueType?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15374657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com