GurdeepS
GurdeepS

Reputation: 67223

Where is the class assigned to when stored in a struct?

I read a thread (which had the input of Marc Gravell and Jon Skeet) that mentioned if a struct is in a class, that struct is stored on the heap like the class.

What if a class is a member of a struct? Where does the class get assigned to?

Thanks

Upvotes: 3

Views: 183

Answers (2)

leppie
leppie

Reputation: 117230

Still on the heap. The struct will only contain a reference to the class instance (like a pointer).

Upvotes: 3

Marc Gravell
Marc Gravell

Reputation: 1062780

If a class is a member of a struct, then only the reference is stored in the struct (i.e. the 32/64-bit address to the instance). The instance of a class is always on the heap.

Upvotes: 12

Related Questions