C# - 尝试从double转换为int,但失败了

Bil*_*lie 1 c# casting

我尝试用2来表示数字.我写道:

int xy = y - x;
double xx = (double)xy;
distance = Math.Pow(xx, (double) 2.0);
Run Code Online (Sandbox Code Playgroud)

x,y是整数.

我收到此错误:

不能隐式地将类型'double'转换为'int'.存在显式转换(您是否错过了演员?)

为什么会出错?这两个参数都是double打字的.

此代码下方绘制的错误红线: Math.Pow(xx, (double) 2.0);

I4V*_*I4V 9

我猜distance是被宣布为int

 distance = (int)Math.Pow(xx, (double) 2.0);
Run Code Online (Sandbox Code Playgroud)