带有引用类型变量的对象类型装箱

编程入门 行业动态 更新时间:2024-10-25 16:25:01
本文介绍了带有引用类型变量的对象类型装箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

装箱是将值类型分配给对象类型时.将引用类型分配给对象时是否相同?

Boxing is when a value type is assigned to an object type. Is it the same when a reference type is assigned to an object?

分配类型(不是对象)后,会发生什么?那个拳击也是吗?

When a type (which isn't object) is assigned, what happens? Is that boxing too?

int num=5; object obj = num; //boxing ////////////////////// MyClass my = new MyClass(); object obj = my; //what is name this convert (whethere is boxing?)

推荐答案

我假设您的意思是

string s = "hello"; object x = s; // no boxing, just implict conversion to base-type.

之所以可行,是因为 System.String 与所有其他类一样,是从 System.Object :

This works because System.String, like all other classes, derives from System.Object:

public sealed class String : Object { ... }

更多推荐

带有引用类型变量的对象类型装箱

本文发布于:2023-11-02 13:57:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552588.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   变量   对象

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!