MSDN says that
开发者_如何学GoThe 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?
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."
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.
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.
Boxing is only done on value types. I'm wondering though why MSDN doesn't state it more precisely.
精彩评论