## Double的“==”运算符的定义？内容来源于 Stack Overflow，并遵循CC BY-SA 3.0许可协议进行翻译与使用

• 回答 (2)
• 关注 (0)
• 查看 (24)

```public static bool operator ==(Double left, Double right) {
return left == right;
}```

• 这样的定义有什么意义？
• 它是如何工作的？
• 为什么不创建一个无限递归呢？

### 2 个回答

```double d1 = 1.1;
double d2 = 2.2;

MethodInfo mi = typeof(Double).GetMethod("op_Equality", BindingFlags.Static | BindingFlags.Public );

bool b = (bool)(mi.Invoke(null, new object[] {d1,d2}));```

```IL_0000:  nop
IL_0001:  ldc.r8      9A 99 99 99 99 99 F1 3F
IL_000A:  stloc.0     // d1
IL_000B:  ldc.r8      9A 99 99 99 99 99 01 40
IL_0014:  stloc.1     // d2
IL_0015:  ldtoken     System.Double
IL_001A:  call        System.Type.GetTypeFromHandle
IL_001F:  ldstr       "op_Equality"
IL_0024:  ldc.i4.s    18
IL_0026:  call        System.Type.GetMethod
IL_002B:  stloc.2     // mi
IL_002C:  ldloc.2     // mi
IL_002D:  ldnull
IL_002E:  ldc.i4.2
IL_002F:  newarr      System.Object
IL_0034:  stloc.s     04 // CS\$0\$0000
IL_0036:  ldloc.s     04 // CS\$0\$0000
IL_0038:  ldc.i4.0
IL_0039:  ldloc.0     // d1
IL_003A:  box         System.Double
IL_003F:  stelem.ref
IL_0040:  ldloc.s     04 // CS\$0\$0000
IL_0042:  ldc.i4.1
IL_0043:  ldloc.1     // d2
IL_0044:  box         System.Double
IL_0049:  stelem.ref
IL_004A:  ldloc.s     04 // CS\$0\$0000
IL_004C:  callvirt    System.Reflection.MethodBase.Invoke
IL_0051:  unbox.any   System.Boolean
IL_0056:  stloc.3     // b
IL_0057:  ret ```

```ldarg.0
ldarg.1
ceq
ret```