Defining an Implicit Conversion : Implicit Conversion Operator « Operator Overload « C# / CSharp Tutorial






class Point
{
    public int X;
    public int Y;
   
    public static implicit operator double(Point RValue)
    {
        double Distance;
        double Sum;
   
        Sum = (RValue.X * RValue.X) + (RValue.Y * RValue.Y);
        Distance = System.Math.Sqrt(Sum);
        return Distance;
    }
   
    public static void Main()
    {
        double Distance;
        Point MyPoint = new Point();
   
        MyPoint.X = 100;
        MyPoint.Y = 200;
        Distance = MyPoint;
        System.Console.WriteLine(Distance);
    }
}








8.6.Implicit Conversion Operator
8.6.1.An example that uses an implicit conversion operator.
8.6.2.Defining an Implicit Conversion