c# - When accessing value-type properties of an object stored in a dynamic, does it cause boxing of those properties' values? -
consider following code...
public class valueholder<t> { public t heldvalue{ get; set; } }
when assigning x here, there of course no boxing.
var intvalueholder = new valueholder<int>(){ heldvalue = 44 }; int x = intvalueholder.heldvalue;
but in case valueholder stored in dynamic? there boxing when assigning heldvalue y?
dynamic dynamicvalueholder = new valueholder<int>(){ heldvalue = 44 }; int y = dynamicvalueholder.heldvalue;
i'm not sure mechanism dynamic member resolution i'm not sure how check this.
note
i not storing value-type in dynamic, examples this...
dynamic x = 44; // 44 boxed
...is not i'm asking. in example i'm storing object in dynamic no boxing needed there, when access value-type property on object, that value-type property boxed? clears i'm after here.
i quote this msdn document:
" type dynamic behaves type object in circumstances. however, operations contain expressions of type dynamic not resolved or type checked compiler. compiler packages information operation, , information later used evaluate operation @ run time. part of process, variables of type dynamic compiled variables of type object. therefore, type dynamic exists @ compile time, not @ run time. "
so
dynamic dynamicvalueholder = new valueholder<int>(){ heldvalue = 44 };
won't deal boxing.
but dynamic compiled object , object reference type. when refernce type created, can contain value type properties , properties stored on heap because part of reference type (for more infos @ this c-sharpcorner article. then
int y = dynamicvalueholder.heldvalue;
implies unboxing.
Comments
Post a Comment