title: How do dynamic and value types work?
body: <p>There is a small piece of code that I can not understand:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          var ts = new TestStruct() { a = 2 };
          object ots = ts;
          dynamic dts = ots;
          ts.a = 6;
          dts.a = 4;
          Console.WriteLine(dts.GetType()); //Type is TestStruct
          Console.WriteLine("ts.a =" + ts.a); //6
          Console.WriteLine("unboxed ts.a =" + ((TestStruct)ots).a); //4
          Console.WriteLine("dts.a =" + dts.a); //4
          Console.ReadKey();
      }
  }
  
  public struct TestStruct
  {
      public int a;
  }
  </code></pre>
  
  <p><code>dts</code> and <code>ots</code> refer to the same variable on the heap, but <code>GetType</code> returns for <code>dts</code> <code>TestStruct</code>. <code>dts</code> is <code>TestStruct</code> but stored on the heap? Or something I do not understand?</p>