Boxing & Unboxing in C#
Boxing is an implicit conversion of a value type to the type object.
int i = 123; // A value type
object box = i; // Boxing
Unboxing is an explicit conversion from the type object to a variable type.
int i = 123; // A value type
object box = i; // Boxing
int j = (int)box; // Unboxing
Casting: casting is the process of converting a variable from one type to another( from a string to an integer)
In a simple language we can define:
Boxing - converting value type to reference type
Unboxing - converting reference type to value type.
Hope this will make you understand Boxing and Unboxing in C#.
int i = 123; // A value type
object box = i; // Boxing
Unboxing is an explicit conversion from the type object to a variable type.
int i = 123; // A value type
object box = i; // Boxing
int j = (int)box; // Unboxing
Casting: casting is the process of converting a variable from one type to another( from a string to an integer)
In a simple language we can define:
Boxing - converting value type to reference type
Unboxing - converting reference type to value type.
Hope this will make you understand Boxing and Unboxing in C#.
Comments
Post a Comment