I know what “boxing” is:
object myBox = 5;
Now I wish to increase my knowledge. Is a special type created for this boxing operation? Or is System.Object used? How does .NET handle boxing?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no special type; a boxed value type is an implementation detail of the runtime. But the easiest way to understand it is to imagine that there is a special type:
Where the type
Box<T>also implements all the methods, interfaces, and so on, of T, for whatever T happens to be. So, for example, you could imagine thatBox<int>has a method ToString which simply calls int.ToString on the value, and returns the result.Boxing is simply a mechanism for getting a reference to something that is not of reference type. You just make a box around the thing and get a reference to the box.