小编Jer*_*urn的帖子

为什么这个类型转换会导致错误?

这按预期工作:

byte b = 7;
var i = (int)b;
Run Code Online (Sandbox Code Playgroud)

虽然这引发了InvalidCastException:

byte b = 7;
object o = b;
var i = (int)o;
Run Code Online (Sandbox Code Playgroud)

object当基础类型仍然存在时,为什么转换会失败byte

.net c# casting

6
推荐指数
1
解决办法
123
查看次数

标签 统计

.net ×1

c# ×1

casting ×1