开发者

Object type and boxing

开发者 https://www.devze.com 2023-02-06 21:49 出处:网络
MSDN says that The object data type is the type to and from which objects are boxed. 开发者_如何学GoI thought only value types are boxed? Now I am bit confused. So when I assign reference type va

MSDN says that

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

开发者_如何学Go

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消