简体   繁体   中英

Reference Type and Value Type in Memory

If i have a class Person and this class have data members as FirstName , LastName .

 public Class Person
 {
     public string firstName {get; set;}
     public string lastName   {get; set;}

 }

Class Person is a Reference Type but firstName and lastName are Value Type. Then how this would be stored? Would Class Person be stored on Heap and firstName and lastName would be stored on stack? Can someone please help me understand how this works exactly?

In this case, everything will be stored on the heap, because everything is contained within a reference type.

Note also that string is a reference type anyway (although MS does everything to make it look like a value type).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM