Memory structure for reference and value types

160 views Asked by At

I am new to c# and now in learning phase .I got confused with reference and value types . I google on this but did not find an answer which makes me understand .

Here is my class . I want to know how all this types are getting stored inside heap/stack .

class Demomemory
{
      int var ;
      string strVar ;
      public DemoClass DC = new DemoClass(); //Another class object
      public Demomemory(int x ,int y)
      {
         int z = x+ y ;
      }
}

Can anyone please tell me with some diagram how the above variables(var , strVar , DC , x , y , z) are getting stored inside memory . I usually see some statements like DC is reference to the actual object . What exacly is this reference .

I am new to c# , So please help me on this . Thanks in advance .

1

There are 1 answers

0
Ehsan On

I want to know how all this types are getting stored inside heap/stack .

You need not go anywhere other than Eric Lippert's article here. It discusses every bit of value and reference type in detail.