我尝试战俘一批具有2我写道:C# - 试图从双强制转换为int,但未能
int xy = y - x;
double xx = (double)xy;
distance = Math.Pow(xx, (double) 2.0);
x
,y
是整数。
我收到此错误:
cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)
这是为什么错误?这两个参数都是double
键入的。下面这段代码绘制
错误红线: Math.Pow(xx, (double) 2.0);
什么是“距离”? – xxbbcc
您的标题有误。你试图从'double'转换为'int',而不是相反。 –
如果您不需要将'xy'转换为'double','int'可以隐式转换为'double'。你可以将'xy'右移到'Math.Pow'。你也不需要将'2.0'转换为'double'。在它们中带有小数的文字数字已经是'double'类型的。当然,这与答案没有关系。 – Servy