Search

You may have heard the term “boxing” in reference to C# or .NET programming. What is it, exactly?

In simple terms, it refers to ‘converting’ a value type to a reference type.

Here’s a quick example:

 int i = 1;
 object o = i; // boxing
 int j = (int) o; // unboxing
 

Note that this is possible because object is the ultimate base class.

Generally, boxing is something you want to avoid if possible, since it hinders performance if it’s being performed multiple times, and it’s not always obvious when it happens.

One Response to “Boxing and Unboxing”

Leave a Reply