A simple boxing/unboxing example


   
 
/*
C#: The Complete Reference 
by Herbert Schildt 

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


// A simple boxing/unboxing example. 
using System; 
 
public class BoxingDemo { 
  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); 
  } 
}


           
         
     


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