A boxing/unboxing example. : Boxing Unboxing : Data Type C# Examples


C# Examples » Data Type » Boxing Unboxing »

 

A boxing/unboxing example.









    
using  System;  
  
class  MainClass  {  
    public  static  void  Main()  {  
        int  x;  
        object  obj;  
  
        x  =  10;  
        obj  =  x;  //  box  x  into  an  object  
  
        int  y  =  (int)obj;  //  unbox  obj  into  an  int  
        Console.WriteLine(y);  
    }  
}
    
   
  
   



Output

10


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Boxing Unboxing