LaysomeSmith
LaysomeSmith

Reputation: 681

Base class of struct construct in C#

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

Upvotes: 7

Views: 7346

Answers (1)

user166390
user166390

Reputation:

The hierarchies (skipping any class subtypes) are:

  1. struct .. -> ValueType -> Object

  2. 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

Upvotes: 12

Related Questions