简体   繁体   English

对象类型和装箱

[英]Object type and boxing

MSDN says that MSDN说

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? 因此,当我将引用类型变量分配给对象变量时,将其装箱?

It just states that System.Object is the type used when any object is boxed. 它只是指出System.Object是装箱任何对象时使用的类型。

In other words, when a value type is boxed, it is boxed within System.Object type. 换句话说,将值类型装箱后,会将其装在System.Object类型内。

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." object数据类型是装箱和从中装的类型。”

Yes only value types are boxed. 是的,仅将值类型装箱。 Boxing a value type packages it inside an instance of the Object reference type. 将值类型装箱将其打包在Object引用类型的实例中。 What this statement says is that it is System.Object which is used to box/unbox value types to and from. 该语句表示的是System.Object,用于对值类型进行装箱/拆箱。

Boxing is only done on value types. 装箱仅对值类型进行。 I'm wondering though why MSDN doesn't state it more precisely. 我想知道为什么MSDN没有更准确地陈述它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM