hor*_*rgh 6 c# interface implicit-conversion
说,我有一个界面
public interface ISomeControl
{
Control MyControl { get; }
...
}
Run Code Online (Sandbox Code Playgroud)
是否可以像这样定义smth:
public static implicit operator Control(ISomeControl ctrl)
{
return ctrl.MyControl;
}
Run Code Online (Sandbox Code Playgroud)
或者更确切地说,为什么我不能在C#中这样做?
如果您有子类Control,并且该子类实现了该ISomeControl接口,该怎么办?
class SomeControl : Control, ISomeControl {}
Run Code Online (Sandbox Code Playgroud)
现在演员阵容不明确 - 内置的向上翻译和用户定义的转换.因此,您无法为接口提供用户定义的转换.
| 归档时间: |
|
| 查看次数: |
1770 次 |
| 最近记录: |