隐式向上转换是否发生在Visual C#中?

Mah*_*esh 3 c#

double b = 1.5 * a,哪里afloat变量.

a被强制转换为double上的Visual Studio 2010在Visual C#执行乘法之前?

Mar*_*ell 8

如果这是你的意思,浮点数将被转换为double 乘.

float a = 1.2F;
double b = 1.5*a;
Run Code Online (Sandbox Code Playgroud)

得到:

L_0000: nop <========== just because I'm in debug mode
L_0001: ldc.r4 1.2 <=== load the float value 1.2
L_0006: stloc.0 <====== store in "a"
L_0007: ldc.r8 1.5 <=== load the double value 1.5
L_0010: ldloc.0 <====== load "a"
L_0011: conv.r8 <====== widen the value we obtained from "a" to become a double
L_0012: mul <========== multiply as double
L_0013: stloc.1 <====== store in "b"
L_0014: ret <========== all done
Run Code Online (Sandbox Code Playgroud)

请注意,这只会更改堆栈中值的副本a ; a本身不受影响.