User-Defined Conversions : Conversion Operator Overload : Operator Overload C# Examples


C# Examples » Operator Overload » Conversion Operator Overload »

 

User-Defined Conversions









    
using  System;

public  class  MyType
{
        public  static  implicit  operator  YourType(MyType  s)  
        {  
                Console.WriteLine("conversion  here");
                return(new  YourType());
        }
}

public  class  YourType
{
}

public  class  YourDerivedType:  YourType
{
        
}
public  class  Test
{
        public  static  void  Main()
        {
                MyType  myType  =  new  MyType();
                YourType  tb  =  (YourType)  myType;
        }
}
    
   
  
   



Output

conversion here


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Operator Overload
» Conversion Operator Overload