Search code examples
.netc#-4.0dynamicvalue-typereference-type

Where are the values of variables marked as 'dynamic' stored?


On .net, value types are stored on the stack and reference types on the heap (and it's reference on the stack).

But if a variable is marked as dynamic, is this rule still valid based on the run-time type of the data?

I was looking for some reference that points to this, but didn't find any.


Solution

  • A variable of type dynamic is a System.Object at runtime. So it is always a reference to an object that's stored on the GC heap. If you assign a value type value to the variable then it will be boxed with a standard boxing conversion.