title: How are objects stored in memory?
body: <p>I'm trying to understand how objects are stored in memory using the .NET Framework.</p>
  
  <p>Given the following <code>person</code> class:</p>
  
  <pre><code>public class Person
  {
      public string name { get; set; }
  
      public int age { get; set; }
  }
  </code></pre>
  
  <p>I believe an initiated variable of type <code>Person</code> would have the following structure in memory:
  <a href="https://i.stack.imgur.com/qIhid.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qIhid.png" alt="Person Memory Structure"></a></p>
  
  <p>Questions:</p>
  
  <ul>
  <li><p>Firstly, are their any major / obvious flaws in my understanding? (I'm almost certain there is, as it just seems way to in-efficient to handle objects in the way I am describing; especially in the way the <code>name</code> pointer points to the char collection for the string member)</p></li>
  <li><p>Secondly, for value type members of a class (I.E <code>Age</code>), are they stored within the object itself (so within the same memory address as the object), or do they get allocated their own address, and the object then points to it? (Such as my diagram shows)</p></li>
  <li><p>Similar to the above question, but for reference type members, does the object hold a pointer to the pointer? (I.E The name pointer referencing the char collection in my diagram)</p></li>
  <li><p>Finally, Would it make a difference if the members of my <code>Person</code> class were fields rather than properties?</p></li>
  </ul>
  
  <p><strong>Update:</strong> Updated diagram based on answers from Sweeper &amp; Tim, which I believe is now correct.</p>
  
  <p><a href="https://i.stack.imgur.com/uxRw9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uxRw9.png" alt="Correct Diagram"></a></p>
  
  <p>Note: <em>Pointer</em> changed to reference as this is managed code.</p>