Boxing also occurs when passing values

image_pdfimage_print

   
 
/*
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; 
  } 
}


           
         
     


This entry was posted in Data Types. Bookmark the permalink.