斜面投浮到INT如果对象 [英] Cant cast float to int if object
本文介绍了斜面投浮到INT如果对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码运行正常
float ff = 5.5f;
int fd = (int) ff;
Console.Write(fd);
在哪里,因为这代码犯规
Where as this code doesnt
float ff = 5.5f;
object jf = ff;
int fd = (int) jf;
Console.Write(fd);
什么规则在亚军导致这种情况出现?
What rule in the runner causes this to happen?
推荐答案
您可以投一个浮点数为int,但你不能投出的盒装的浮动为int - 你必须先拆箱它。
You can cast a float to an int, but you can't cast a boxed float to an int - you have to unbox it first.
int fd = (int)(float)jf;
阅读埃里克利珀的帖子的表示和更多的细节身份。
这篇关于斜面投浮到INT如果对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文