Boxing occurs when passing values : Boxing Unboxing : Data Type C# Examples


C# Examples » Data Type » Boxing Unboxing »

 

Boxing occurs when passing values









    
using  System;  
  
class  MainClass  {  
    public  static  void  Main()  {  
        int  x;  
        
        x  =  10;  
        Console.WriteLine("Here  is  x:  "  +  x);  
  
        //  x  is  automatically  boxed  when  passed  to  sqr()  
        x  =  sqr(x);  
        Console.WriteLine("Here  is  x  squared:  "  +  x);  
    }  
  
    static  int  sqr(object  o)  {  
        return  (int)o  *  (int)o;  
    }  
}
    
   
  
   



Output

Here is x: 10
Here is x squared: 100


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Boxing Unboxing