Day 23 : Boxing and Unboxing
In this blog we are going to understand the concept of boxing and unboxing. Boxing : Boxing is the process of converting a value-type to a reference-type. When CLR(Common Language Runtime) boxes a value-type, it wraps a value inside System.Object instance and stores it on managed heap. In simple words, Boxing is used to store the value type in the garbage collected heap. Boxing is an implicit conversion of value type to object. Example : In above example, 'a' is a int(value-type) have value '200'. After that object 'o' copies value from 'i' i.e boxing. The result of this statement is, it creates object reference 'o' on stack and that references value of type int('i') on heap. We can also perform explicit boxing but it is not required. Example : ...