Michael
Michael

Reputation: 33

Object type and boxing

MSDN says that

The object data type is the type to and from which objects are boxed.

I thought only value types are boxed? Now I am bit confused. So when I assign reference type variable to object variable, its boxing?

Upvotes: 3

Views: 157

Answers (4)

Guffa
Guffa

Reputation: 700342

Only value types are boxed.

So, to be accurate the sentence should be:

"The object data type is the type to and from which values are boxed."

Upvotes: 2

Botz3000
Botz3000

Reputation: 39610

Boxing is only done on value types. I'm wondering though why MSDN doesn't state it more precisely.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038810

Yes only value types are boxed. Boxing a value type packages it inside an instance of the Object reference type. What this statement says is that it is System.Object which is used to box/unbox value types to and from.

Upvotes: 1

decyclone
decyclone

Reputation: 30830

It just states that System.Object is the type used when any object is boxed.

In other words, when a value type is boxed, it is boxed within System.Object type.

Upvotes: 2

Related Questions