gpt4 book ai didi

c# - 引用类型的装箱和隐式转换

转载 作者:太空宇宙 更新时间:2023-11-03 18:09:04 24 4
gpt4 key购买 nike

类型到其基类型的隐式转换是否涉及装箱?

例子:

HttpClient client = new HttpClient();
object o = client;
IDisposable d = client;

如果是这样,装箱引用类型与装箱值类型是否会影响性能?

最佳答案

装箱应用于值类型。

您的示例中没有任何内容演示装箱。您只执行了引用类型的转换。

来自 MSDN :

Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type.

关于c# - 引用类型的装箱和隐式转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20058503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com