相关疑难解决方法(0)

为什么(int)(对象)10m抛出"指定的强制转换无效"异常?

为什么这个显式转换会抛出Specified cast is not valid.异常?

decimal d = 10m;
object o = d;
int x = (int)o;
Run Code Online (Sandbox Code Playgroud)

但这有效:

int x = (int)(decimal)o;
Run Code Online (Sandbox Code Playgroud)

c# casting

39
推荐指数
3
解决办法
2万
查看次数

标签 统计

c# ×1

casting ×1