Answer: Boxing and Unboxing both are used for type conversion but have some difference:
Boxing:
Boxing is the process of converting a value type data type to the object or to any interface data type which is implemented by this value type. When the CLR boxes a value means when CLR is converting a value type to Object Type, it wraps the value inside a System.Object and stores it on the heap area in application domain.
Example:
Unboxing:
Unboxing is also a process which is used to extract the value type from the object or any implemented interface type. Boxing may be done implicitly, but unboxing have to be explicit by code.
Example:
The concept of boxing and unboxing underlines the C# unified view of the type system in which a value of any type can be treated as an object.
Boxing:
Boxing is the process of converting a value type data type to the object or to any interface data type which is implemented by this value type. When the CLR boxes a value means when CLR is converting a value type to Object Type, it wraps the value inside a System.Object and stores it on the heap area in application domain.
Example:
Unboxing:
Unboxing is also a process which is used to extract the value type from the object or any implemented interface type. Boxing may be done implicitly, but unboxing have to be explicit by code.
Example:
The concept of boxing and unboxing underlines the C# unified view of the type system in which a value of any type can be treated as an object.
No comments:
Post a Comment