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 the ISomeControl
interface.
class SomeControl : Control, ISomeControl {}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With