110,566
社区成员
发帖
与我相关
我的任务
分享
byte value = 0;
value = value | (byte)(1 << i);
value |= (byte)(1 << i);
int i = int.Parse("1");
byte value = 0;
var a = value | (byte)(1 << i);
对应生成的IL代码如下:
// [52 13 - 52 36]
IL_0000: ldstr "1"
IL_0005: call int32 [mscorlib]System.Int32::Parse(string)
IL_000a: stloc.0 // i
// [53 13 - 53 28]
IL_000b: ldc.i4.0
// [54 13 - 54 44]
IL_000c: ldc.i4.1
IL_000d: ldloc.0 // i
IL_000e: ldc.i4.s 31 // 0x1f
IL_0010: and
IL_0011: shl
IL_0012: conv.u1
IL_0013: or
另一段代码:
int i = int.Parse("1");
byte value = 0;
value |= (byte)(1 << i);
生成的IL代码:
// [60 13 - 60 36]
IL_0000: ldstr "1"
IL_0005: call int32 [mscorlib]System.Int32::Parse(string)
IL_000a: stloc.0 // i
// [61 13 - 61 28]
IL_000b: ldc.i4.0
// [62 13 - 62 37]
IL_000c: ldc.i4.1
IL_000d: ldloc.0 // i
IL_000e: ldc.i4.s 31 // 0x1f
IL_0010: and
IL_0011: shl
IL_0012: conv.u1
IL_0013: or
IL_0014: conv.u1