Using LinqPad, it's easy to take a look at IL to see what happens. Basically, Point converted to PointF , and then the equality == method is called for PointF .
For example, using this code:
System.Drawing.PointF myPointF = new System.Drawing.PointF(1.1f ,1.1f); System.Drawing.Point myPoint = new System.Drawing.Point(1,1); bool equal = (myPointF == myPoint); Console.WriteLine(equal);
Produces the following IL:
IL_0001: ldloca.s 00 // myPointF IL_0003: ldc.r4 CD CC 8C 3F IL_0008: ldc.r4 CD CC 8C 3F IL_000D: call System.Drawing.PointF..ctor IL_0012: nop IL_0013: ldloca.s 01 // myPoint IL_0015: ldc.i4.1 IL_0016: ldc.i4.1 IL_0017: call System.Drawing.Point..ctor IL_001C: nop IL_001D: ldloc.0 // myPointF IL_001E: ldloc.1 // myPoint IL_001F: call System.Drawing.Point.op_Implicit //<- convert Point to PointF IL_0024: call System.Drawing.PointF.op_Equality //<- PointF equality IL_0029: stloc.2 // equal IL_002A: ldloc.2 // equal IL_002B: call System.Console.WriteLine
If you use ILSpy, you can find the contents of both Point.op_Implicit and PointF.op_Equality .
// System.Drawing.Point public static implicit operator PointF(Point p) { return new PointF((float)pX, (float)pY); } // System.Drawing.PointF public static bool operator ==(PointF left, PointF right) { return left.X == right.X && left.Y == right.Y; }
This demonstrates that int values โโare converted to float values โโwhen Point converted to PointF , and then the float values โโfrom the original instance of PointF and the converted PointF > are compared.
source share