Boxing also occurs when passing values : Boxing Unboxing : Data Types C# Source Code


Custom Search

C# Source Code » Data Types » Boxing Unboxing »

 

Boxing also occurs when passing values









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/


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


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Data Types
» Boxing Unboxing