Wednesday, May 30, 2012

Boxing and UnBoxing in .net

C# allows us to convert a Value Type to a Reference Type,and back again to Value Types.
The operation of Converting a Value Type to a Reference Type is called Boxing and the reverse operation is called Unboxing.


 int Val = 1;
 Object Obj = Val; // Boxing (value type to reference type)


  int Val = 1;
  Object Obj = Val; // Boxing
  int i = (int)Obj; // Unboxing (reference type to value type)

No comments:

Post a Comment



Custom Search
Protected by Copyscape Plagiarism Software