课程是盒装的吗? 。网
我想知道,班级会被装箱吗?我一直假设每个类都有一个可以用来标识类的虚拟表,那么它需要装箱吗?
I was wondering, does a class get boxed? I always assumed every class had a virtual table which can be used to identify the class, so does it need to be boxed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只有值类型(结构)才会被装箱。类实例不会被装箱。
Only value types (structs) get boxed. Class instances do not get boxed.
不。类是引用类型,因此不需要装箱。装箱用于将值表示为对象(以便提供 .NET 的统一类型系统)。由于类的实例已经是对象,因此它们永远不需要装箱。
No. Classes are reference types so no need for boxing. Boxing is used to represent values as objects (in order to provide .NET's unified type system). As instances of classes are already objects they never need to be boxed.
不,他们不是。
装箱是指将原始类型(int、char、long 等)包装到类中(即装箱)。
No they are not.
Boxing referes to a primite type (int, char, long etc...) being wrapped into a class (i.e. boxed).