What makes ValueType class Special?

前端 未结 3 1280
后悔当初
后悔当初 2021-01-02 04:39

When I trying to define a class which inherits from System.ValueType or System.Enum class, I\'m getting an error:

Cannot derive fro         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-02 05:34

    Microsoft does not publish its C# compiler source code, so we can only guess the check is embedded at compiler level.

    Mono's C# compiler performs this kind of check at compile time, which you can see around line 2790 in Class.ResolveBaseTypes method,

    https://github.com/mono/mono/blob/master/mcs/mcs/class.cs

提交回复
热议问题