Boxing and Unboxing
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 CLRlic 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:
public void fnBoxing()
{
int i=5;
object o=i; //implicit Boxing
}
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:
public void fnUnboxing()
{
object o=5;
int i=(int)o;//explicit Unboxing
}
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 CLRlic 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:
public void fnBoxing()
{
int i=5;
object o=i; //implicit Boxing
}
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:
public void fnUnboxing()
{
object o=5;
int i=(int)o;//explicit Unboxing
}
Comments
Post a Comment