Rob*_*ert 5 c# boxing unboxing
有2个和3个装箱/拆箱的例子吗?
1)文档示例:
int i = 123;
object iBoxed = i;
i = (int) iBoxed;
Run Code Online (Sandbox Code Playgroud)
2:拳击/拆箱也是吗?
int i = 123;
object iBoxed = i;
i = Int32.Parse(iBoxed.ToString());
Run Code Online (Sandbox Code Playgroud)
3:拳击/拆箱也是吗?
int i = 123;
object iBoxed = i;
i = Convert.ToInt32(iBoxed);
Run Code Online (Sandbox Code Playgroud)
我假设在所有例子中技术上都是一样的.
所以我猜2和3是拳击/拆箱的例子?
在所有三个例子中:
iBoxed是盒装副本i.
在示例2中:这里没有涉及拆箱,因为ToString最终将解析的虚拟方法将被解析int.ToString,然后在堆栈上int.Parse返回非盒装int.
在示例3中:
iBoxed将在方法体中取消装箱Convert.ToInt32并再次作为非盒装整数返回.
| 归档时间: |
|
| 查看次数: |
1715 次 |
| 最近记录: |