Defining an Implicit Conversion : Implicit Conversion Operator : Operator Overload C# Examples


C# Examples » Operator Overload » Implicit Conversion Operator »

 

Defining an Implicit Conversion









    
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);
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Operator Overload
» Implicit Conversion Operator