I have a class with a simple System.Drawing.Point (int, int).
public class Foo
{
public Point Point;
}
I need that this class implement an interface with a PointF (float, float) :
public interface IPointable { PointF Point { get; } }
Of course, when I try Foo : IPointable, I have
Error 7 'Foo' does not implement interface member 'Pointable.Point'
So, I have change my Foo class with
public class Foo
{
public Point IntPoint;
public PointF Point { get { return IntPoint; } }
}
OUHAH, I compile. That’s because Point have a implicit conversion to PointF :
public static implicit operator PointF(Point p);
But I feel dirty.
Foo have a Point with int coordinate, and this is important for a lot of my code. But sometimes, when Foo only need to be IPointable, his int-ness is not so much important.
Is there a way to not add a silly property to my class, and still Foo can be using the IPointable interface?
You can implement interface explicitly:
Now
PointFproperty is only visible form variables that are typedIPointable.