Will the following code cause boxing of the integer passed into the call to GenericMethod?
void GenericMethod<T>(T value)
{
int test = (dynamic)value;
}
void Main()
{
GenericMethod(100);
}
According to C# specification §4.7 The dynamic type:
dynamicis considered identical toobjectexcept in the following respects:
Operations on expressions of type
dynamiccan be dynamically bound (§7.2.2).Type inference (§7.5.2) will prefer
dynamicoverobjectif both are candidates.
So, casting to dynamic cause boxing in the same way as casting to object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With