Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type. When the common language runtime (CLR) boxes a value type, it wraps the value inside a System. Object instance and stores it on the managed heap. Unboxing extracts the value type from the object.
To assign an object to an integer type, we need to cast it to int type. This casting is called unboxing.
Boxing is the process of converting a value type to an object type. When the common language runtime boxes a value type, it wraps the value inside a system. object instance and stores it on the managed heap. Unboxing involves manually extracting the value type from the object.
Boxing is an implicit conversion process. Unboxing is the explicit conversion process. Here, the value stored on the stack copied to the object stored on the heap memory. Here, the object stored on the heap memory copied to the value stored on the stack .
When we convert the data types between primitive data types it is called as data type casting.
But when convert between ValueType and ReferenceType we call it as boxing and unboxing.
Can boxing and unboxing also be called casting?
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