Why can't type values ​​be deduced in C #?

I know that all types of values ​​are produced implicitly from System.ValueType. and structures can implement interfaces, but I need to know why they cannot be inferred from value types in C #.

+4
source share
1 answer

Firstly, value types do not have an object header (because they are not objects), so there would be no way to identify the actual type or do a virtual dispatch.

Secondly - how could you add fields to subtypes? The size must be known to the compiler (for stack space, etc.), therefore:

Foo foo = ... 

should always take the same space.

Similarly, an abstract base type will not work, since you can always build a structure.

In principle, these would be terrible distorted things, crippled and ugly.

I am wondering if you need a subtype of value - this is like confusing using a structure.

+14
source

All Articles