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.

Boxing

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

UnBoxing

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

No comments:

Post a Comment

Comments

Protected by Copyscape Plagiarism Software