User-Defined Conversions: Conversion Lookup : Conversion Operator Overload « Operator Overload « C# / CSharp Tutorial






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;
    }
}
conversion here








8.4.Conversion Operator Overload
8.4.1.There are two forms of conversion operators, implicit and explicit
8.4.2.There are a few restrictions to conversion operators
8.4.3.User-Defined Conversions: Conversion Lookup
8.4.4.User-Defined Conversions