value type inheritance
When dealing with value types, I met with two conflicting points,
1. We can not inherit one value type from another, for example, we can not make a struct inherit from another struct; -- I think it means there is no inheritance or derivation for value types.
2. All value types are inherits from ValueType, and ValueType is inherits from Object, seems value types could have inheritance or derivation?
How do you understand the two conflicting points? :-)
thanks in advance,
There is a difference between "int" and "System.Int32". One is a primitive type, one is a class. One can be inherited, one cannot. C# automatically converts between these two as needed so the user never has to think about it (both for good and bad, as seen by this post). The distinction is much clearer in say Java where you have to explicitly convert.
I do not agree. In IL code, int is the same as Int32. :-)
Originally Posted by Magos
It's called boxing and unboxing, a class wrapping a primitive type.