Reputation: 33
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
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
Reputation: 39610
Boxing is only done on value types. I'm wondering though why MSDN doesn't state it more precisely.
Upvotes: 0
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
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