问题
http://msdn.microsoft.com/en-us/library/ah19swz4(v=VS.71).aspx
As per the above link….. “Structs, however, inherit from the base class Object……”
As per the below link http://msdn.microsoft.com/en-us/library/system.valuetype.aspx Struct is implemented after ValueType in the hierarchy.
“struct” is derived from which class? Or compiler treats “struct” reserve word to make any declaration using “struct” as value type? Missing the small thread in overall understanding. Thank you for your help. Smith
回答1:
The hierarchies (skipping any class subtypes) are:
struct .. -> ValueType -> Object
class .. -> Object
Demo:
struct S {}
class C {}
// or see `is` as per Jeff Mercado's comment
typeof(ValueType).IsAssignableFrom(typeof(S)); // True
typeof(object).IsAssignableFrom(typeof(S)); // True
typeof(ValueType).IsAssignableFrom(typeof(C)); // False
typeof(object).IsAssignableFrom(typeof(C)); // True
来源:https://stackoverflow.com/questions/11461789/base-class-of-struct-construct-in-c-sharp