我有一个这个简单的程序,可以在一个可以为空的long上切换:
class Program
{
static void Main(string[] args)
{ Console.WriteLine(Test(1)); }
private static string Test(long? orderId)
{
switch (orderId)
{
case 1:
return "1";
default:
return "default";
}
}
}
Run Code Online (Sandbox Code Playgroud)
在VS 2013中编译之后,我总是得到"1"作为输出.在VS 2015中编译后,我总是将"默认"作为输出.
只有当Test()的参数是long(不是int)时才会发生.
我已经反编译然后il代码和(在我看来)在通过"beq.s"比较值之前缺少"conv.i8"(VS 2013编译器发出它):
.method private hidebysig static string
Test(valuetype [mscorlib]System.Nullable`1<int64> orderId) cil managed
{
// Code size 46 (0x2e)
.maxstack 2
.locals init ([0] valuetype [mscorlib]System.Nullable`1<int64> V_0,
[1] valuetype [mscorlib]System.Nullable`1<int64> V_1,
[2] int64 V_2,
[3] string V_3)
//000011: private static string Test(long? orderId)
//000012: {
IL_0000: nop …Run Code Online (Sandbox Code Playgroud)