Hello All,

Where is the memory allocated for Value TYpes which are part of
a class, when you create an instance of the class, it goes on heap, where is the memory allocate members which are of value types in the class?


Class Customer
{
private int _customerID,
private string _SSN;


}

Regards
LinkPraveen.

All the fields of a class are allocated in the same place, right next to one another. That means variables whose type is some value type are allocated in the same place as variables whose type is some reference type. Of course, the amount of space needed per variable might be different.

(Edit: I'm saying that the int "_customerID" will get allocated right next to the string reference "_SSN". _SSN is a reference that points to a string allocated elsewhere.

Edited 7 Years Ago by Rashakil Fol: n/a

All the fields of a class are allocated in the same place, right next to one another. That means variables whose type is some value type are allocated in the same place as variables whose type is some reference type. Of course, the amount of space needed per variable might be different.

(Edit: I'm saying that the int "_customerID" will get allocated right next to the string reference "_SSN". _SSN is a reference that points to a string allocated elsewhere.

I meant to say that "Value Types" goes into class and "Reference" Types goes into HEAP, in this case when we have both types with a class,
will the value types part of class get allocated on stack and reference types on heap, or class gets allocated in HEAP with both value and referene types on HEAP?

This article has been dead for over six months. Start a new discussion instead.