Stack & heap understanding question

Posted by Petr on Stack Overflow See other posts from Stack Overflow or by Petr
Published on 2010-04-01T09:09:59Z Indexed on 2010/04/01 9:13 UTC
Read the original article Hit count: 552

Filed under:
|
|

Hi, I would really appreciate if someone could tell me whether I understand it well:

class X
{
    A a1=new A() //reference on the stack, object value on the heap
    a1.VarA=5; //on the stack - value type
    A a2=new A() //reference on the stack, object value on the heap
    a2.VarA=10; //on the stack - value type

   a1=a2; //on the stack, the target of a1 reference is updated to a2 value on the heap

  //also both a1 and a2 references are on the stack, while their "object" values on the heap. But what about VarA variable, its still pure value type?

}
class A
{
int VarA;
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about memory-management