Boxing vs Un Boxing in C#

 

Boxing UnBoxing

Boxing and unboxing in C# allows developers to convert .NET data types from value type to reference type and vice versa. Converting a value type to a reference type is called called boxing in C# and converting a reference type to a value type is called unboxing in C#. 

  • class Test  

  • {  

  •     static void Main()  

  •     {  

  •         int i = 1;  

  •         object o = i; // boxing  

  •         int j = (int)o; // unboxing  

  •     }  

  • }  


Comments

Popular posts from this blog

Performance Optimization in Sitecore

Strategies for Migrating to Sitecore from legacy or upgrading from older Sitecore

Azure Event Grid Sample code