I know that all value types are derived implicitly from the System.ValueType. and structs can implement interfaces, but I need to know why cannot derive from value types in C#.
Firstly, value-types have no object header (because they aren't objects), so there would be no way to identify the actual type, or to do virtual dispatch.
Secondly - how could you add fields to sub types? The size has to be known by the compiler (for stack space etc), so:
Foo foo = ...
must always take the same amount of space.
Likewise, an abstract base-type wouldn't work, as you can always construct a struct.
Basically, they would be horrible malformed things, crippled and ugly.
I find it interesting that you would want a subtype of a value - that sounds a bit like a confused usage of a struct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With