Tuesday, 14 December 2010

How to use Boxing in C#

Boxing is a method to convert any datatype to object type. All datatypes in C# are derived from base class �object�. So you can directly convert a type to object type. The below code will help you to convert into object type.

class myclass
{
   static void Main()
   {
      int myinteger = 12;
      object obj = myinteger;      // boxing

   }
}

In the above example we are trying to convert int type to object type and it is successfully converted.

 

 

No comments:

Post a Comment