0

I am writing my own class to mimic the PointF class in .NET.

public class PointD
{
    public static readonly PointD Empty;
    public double X, Y;
    // ... Other functions
}

In my example, how do I use the field Empty? When I compare it, is it something like:

PointD myPoint;
if(myPoint == PointD.Empty) // do something
John Tan
  • 1,331
  • 1
  • 19
  • 35
  • 1
    You need to override the == operator, != operator, and the Equals method. – Ron Beyer Apr 30 '15 at 02:08
  • 1
    Take a look at the PointF source code to see how Microsoft does it: http://www.dotnetframework.org/default.aspx/Net/Net/3@5@50727@3053/DEVDIV/depot/DevDiv/releases/whidbey/netfxsp/ndp/fx/src/CommonUI/System/Drawing/Advanced/PointF@cs/2/PointF@cs – Ron Beyer Apr 30 '15 at 02:10
  • you can override the operator, or you can use a nullable type too `PointD?` then you can `if(myPoint == null)` – bto.rdz Apr 30 '15 at 02:13
  • @bto.rdz No, PointD by virtue of being a class is already nullable. PointF is not comparable to null because its a struct (value type). – Ron Beyer Apr 30 '15 at 02:15

0 Answers0