How do ValueTypes derive from Object (ReferenceType) and still be ValueTypes?

后端 未结 6 1871
闹比i
闹比i 2020-11-22 17:20

C# doesn\'t allow structs to derive from classes, but all ValueTypes derive from Object. Where is this distinction made?

How does the CLR handle this?

6条回答
  •  时光说笑
    2020-11-22 18:07

    Small correction, C# doesn't allow structs to custom derive from anything, not just classes. All a struct can do is implement an interface which is very different from derivation.

    I think the best way to answer this is that ValueType is special. It is essentially the base class for all value types in the CLR type system. It's hard to know how to answer "how does the CLR handles this" because it's simply a rule of the CLR.

提交回复
热议问题