Boxing & Unboxing in C#

Boxing is an implicit conversion of a value type to the type object.

                      int i = 123;  // A value type
                      object box = i; // Boxing

Unboxing is an explicit conversion from the type object to a variable type.

                      int i = 123; // A value type
                      object box = i; // Boxing
                      int j = (int)box; // Unboxing

Casting: casting is the process of converting a variable from one type to another( from a string to an integer) 

In a simple language we can define:
Boxing - converting value type to reference type 
Unboxing - converting reference type to value type.

Hope this will make you understand Boxing and Unboxing in C#.

Comments

Popular posts from this blog

Enable HTTP Transport Security (HSTS) in IIS 7

When to use Truncate and Delete Command in SQL

Steps To Create New Project/Team On TFS