Thursday, 26 July 2012

Boxing-UnBoxing in C#


Boxing - Unboxing in C#

Boxing and unboxing is a essential concept in .NET’s type system. With Boxing and unboxing one can link between value-types and reference-types by allowing any value of a value-type to be converted to and from type object. Boxing and unboxing enables a unified view of the type system wherein a value of any type can ultimately be treated as an object.
Converting a value type to reference type is called Boxing. Unboxing is the opposite operation and is an explicit operation.
public class Square
{
public static void main()
{
int i = 1;
object o = i;
int j = (int)o;
}
}


No comments:

Post a Comment