Today we are going to talking about a term known as Boxing. The first thing which would strike your mind once you hear this word is obviously the boxing game. But, what we are going to discuss today has got nothing to do with that.
So, Boxing in programming terminology means, converting a value type to a reference type. I had explained what Value Type and Reference Type is in my previous blogs. The Value Type is stored in the stack portion of the memory. And once it is converted to a reference type, it is stored in the Heap Portion of the memory.
Let’s see how we can perform boxing on a Value Type. And let’s say we have a value type which is an Integer.
Now, in order to convert this Integer to a reference type, we would need an object.
And now, the integer is wrapped in an object which can be similar to placing it in the Box and hence the name! This box is now placed in the heap portion of the memory.