Boxing and Unboxing

Boxing--> It is a process of converting a variable from value type to reference type. it supports two types,
1. Implicit boxing
2. Explicit Boxing
Boxing is 20 times costlier than normal Initialization.
UnBoxing--> Converting a variable from Reference type to value type. it supports only One type,
1. Explicit Boxing
UnBoxing is 4 times Costlier than normal Initialization.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. namespace box   
  6. {  
  7.     class Program   
  8.     {  
  9.         static void Main(string[] args)   
  10.       {  
  11.             int i = 10;  
  12.             object O = i; //Implicit Boxing  
  13.             object X = (object) i; // Explicit Boxing  
  14.             int j = (int) O; // Explicit Unboxing  
  15.             Console.WriteLine("value of i is:-" + i);  
  16.             Console.WriteLine("value of O after Implicit Boxing is :-" + O);  
  17.             Console.WriteLine("value of X after Explicit Boxing is :-" + X);  
  18.             Console.WriteLine("value of j after Explicit UnBoxing is :-" + j);  
  19.             Console.Read();  
  20.         }  
  21.     }  
  22. }