mgroves

Boxing and Unboxing

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.

1 Response to Boxing and Unboxing Article comments Feed

1

UR

I do not know anything about .NET but I do know that a C# is the same as a D Flat.

Posted at February 19, 2009 on 10:12pm

Write a response

Play nice. Be constructive. Allowed HTML tags are: <a>, <strong>, <em> and <blockquote>

« CodeMash wrap-up… Brought to you by th… »