Practice mode C#

In C#, what is boxing?

Correct answer B. Converting a value type to object or an interface type, which copies it into a heap object

Explanation

Boxing happens when a value type such as int is converted to object or to an interface it implements. The runtime allocates an object on the managed heap and copies the value into it. The reverse, unboxing, is an explicit cast back to the exact value type. Because each box costs an allocation, generic collections like List are preferred to ArrayList.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.