Say, I have an interface
public interface ISomeControl
{
Control MyControl { get; }
...
}
Is it possible to define something like this:
public static implicit operator Control(ISomeControl ctrl)
{
return ctrl.MyControl;
}
Or rather why can’t I do that in C#?
What if you had a subclass of
Control, and that subclass implemented theISomeControlinterface.Now a cast would be ambiguous — the built-in upcast, and your user-defined conversion. So you can’t provide user-defined conversions for interfaces.