Illustrate automatic boxing during function call : Boxing Unboxing : Data Type C# Examples


C# Examples » Data Type » Boxing Unboxing »

 

Illustrate automatic boxing during function call









    
using  System;
using  System.Collections;

class  MainClass
{
    static  void  Main(string[]  args)
    {        
        Console.WriteLine("\n*****  Calling  Foo()  *****");
        int  x  =  99;
        Foo(x);
    }
    public  static  void  Foo(object  o)
    {
        Console.WriteLine(o.GetType());
        Console.WriteLine(o.ToString());
        Console.WriteLine("Value  of  o  is:  {0}",  o);

        //  Need  to  unbox  to  get  at  members  of
        //  System.Int32.
        int  unboxedInt  =  (int)o;
        Console.WriteLine(unboxedInt.GetTypeCode());
    }
    
}
    
   
  
   



Output

***** Calling Foo() *****
System.Int32
99
Value of o is: 99
Int32


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Boxing Unboxing