For example int bar, is the value type, is a struct, is this declares
public struct int32:icomparable, IFormattable, IConvertible, IComparable, iequatable
How can you see to inherit from ValueType?? Besides, struct not inherit? Why do you inherit from valuetype?? Puzzled....
Reply:
ValueType is indeed a class type, but his subclass is a value type because the CLR has a special treatment for his subclasses. If the CLR determines that a class inherits from ValueType, it has a characteristic of a value type in memory allocation (for example, directly on the stack). This has little to do with the inheritance hierarchy of the class library.
The compiler on this side of C # has also been specially treated so that value types differ in many ways from class types, for example, we can not declare a value type that inherits from ValueType, and so on.
Simply put, Microsoft has done special processing of value types in. NET to inherit from valuetype. Note: syntax struct is not allowed to inherit, but can implement interfaces. I think Microsoft is disgusting. I always do something that doesn't match with grammar.
Many types do not show inherited base classes,. NET defaults to inherit object, and in string, for example, inherits only the object directly.
struct is directly inherited ValueType, the default, but struct has a feature that can not show the inheritance base class, that is, can only inherit valuetype, so that's it. So it looks like the landlord.
The book says can't inherit base class, because C # is a single inheritance, already have this valuetype, so can't inherit