A boxing/unboxing example. : Boxing Unboxing « Data Type « C# / CSharp Tutorial






using System; 
 
class MainClass { 
  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); 
  } 
}
10








2.53.Boxing Unboxing
2.53.1.A boxing/unboxing example.
2.53.2.Boxing occurs when passing values
2.53.3.Illustrate automatic boxing during function call
2.53.4.Boxing makes it possible to call methods on a value!
2.53.5.Change the value after boxing