Click here to Skip to main content
15,920,602 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I know what is boxing/unboxing in .NET but I don't know which exactly refer "Convert an object to a value type".

If fact I get this interview question

What is boxing in .Net?

A. (None of these)
B. Convert an object to a value type
C. Grouping lines of code into a block
D. Including external resources into a project
Sascha Lefèvre 5-Apr-15 15:10pm    
Multiple choice is the dumbest kind of test ever invented.

You need to understand the difference between value types and reference types to understand boxing (and unboxing).

Its A. You might want to catch up on some .net basics by reading a few beginner tutorials.
It will help you understand these concepts better and answer some of these questions on your own.

Here are a couple of links -
Boxing and unboxing in C#[^]
Boxing and Unboxing[^]
Share this answer
Bastien Vandamme 5-Apr-15 11:44am    
This question is not so basic. I ask it on smarterer and I only get 25% of correct answer.
Sergey Alexandrovich Kryukov 5-Apr-15 12:48pm    
Your logic is wrong. How such percentage can characterize the question.

The question is not basic, of course — it is not a correct question which have any rights to exist, this is a stupid multiple-choice game. Please don't write this kind of trash here, this is just rude. Ask questions if you really want to know something, have a problem, and so on.

Bastien Vandamme 6-Apr-15 4:11am    
But I really want to know. I agree with you. It is not a correct question which have any rights to exist, this is a stupid multiple-choice game. But it is also a question I had during an Interview.
Sergey Alexandrovich Kryukov 6-Apr-15 9:45am    
My other advice would be: don't prepare interview questions, this is useless. Rely on your real knowledge and experience.
Bastien Vandamme 16-Apr-15 23:48pm    
Not so easy. I have a great logic and capacity to build system but I have problem with definitions and theory. I don't know the name of the patterns because most of the time I create them by using my logic. When you are in an Interview this doesn't help. You need to talk with the correct definitions. You act exactly like my interviewers. Because I ask a basic question you think I know nothing. I learned object with Java and some concept in .NET like boxing/unboxing are not really object oriented and if I understand the concept I'm just mixing the two word together. Interviews are a nightmare for me.
As a very quick Google would have told you, Boxing is the process of encapsulating a Value type so that a reference to it can be passed to a method, or included in a collection of objects such as a List
Share this answer
OriginalGriff 5-Apr-15 11:27am    
There is no answer with "convert" except "Boxing does not convert value types variables into anything".

It encapsulates them: it creates a reference type object which holds a value type value (similar to a very, very simple class) and copies the value from the value type into it. The encapsulating reference type instance can then be used to pass a reference, and can be "unboxed" to get the value back later. There is no conversion involved.
Sergey Alexandrovich Kryukov 5-Apr-15 12:50pm    
If this is how you "learn", you whole education is the waste of time. If this is because of your school, I'm really sorry.
Abhinav S 5-Apr-15 11:39am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900