This article talks about one of the most interesting and a little bit puzzling concept of C#. BoxingAny type value or reference can be assigned to an object without an explicit conversion. When the compiler finds a value type where it needs a reference type, it creates an object box into which it places the value.ExplanationFirst of all creating a box of int type (10 bytes) and then creating an object "om" and allocating memory to it.
We can also do that through casting.
Reference Example
OutputScreen: 1Creating a box or a container (Boxing):Screen: 2Quick Points
UnboxingUnboxing is simply the opposite of boxing. In it values are again shifted from the heap to the stack. In unboxing first of all it checks for the boxed object value and then it goes for replica creation or we can say for copying.Explanation
Quick Points
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: