user3478233
user3478233

Reputation: 87

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?

Upvotes: 2

Views: 66

Answers (1)

Thomas Weller
Thomas Weller

Reputation: 11717

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

Upvotes: 3

Related Questions