Why does implicit operator have problems when I try to convert the return type to an object or a one custom type that I have defined myself?
I have no problem when I am trying to convert and return a simple type like an int, like this
public static implicit operator int(MyClass a)
        {
            return 123;
        }
However, when I try to convert the type into an object or a custom type, I will get an error. For example, I will get a compile-time error saying "User-defined conversion to System.Object" if I have something like this:
public static implicit operator object(MyClass a)
{
   return new {};
}
I will get the same kind of error if I have this:
public static implicit operator CustomTestObject(MyClass a)
{
   return new CustomTestObject();
}
How can I convert it to my own custom defined type for return when using an implicit operator?
CustomTestObjectconversion wouldn't work.MyClassandCustomTestObject. In my answer I kind of assumed that one was a base class of the other.MyClassis an ordinary class that inherits from an Object base class. I can understand from your answer how implicitly converting it to object in this case wouldn't have worked. I just realised that in my actual code, the exampleCustomTestObjectis an interface. I believe that since an interface doesn't have any concrete implementation, the conversion wouldn't make sense. Thanks a lot for the answer.operator) is not allowed to or from interfaces. The error message you got should mention interfaces (your question didn't). Some derived class of your class could start implementing the interface. Then it would be confusing for that derived class to be implicitly convertible to the interface (by a simple reference conversion) because it implements it, while at the same time having a user-defined conversion to the same interface. I think that's one of the reasons why they disallowed conversions to/from interfaces.