public class Derived : BaseClass
{
public Derived(string name) : base(name) {}
public static implicit operator BaseClass(Derived derived)
{
return new BaseClass(derived.ColorHex);
}
public static implicit operator Derived(BaseClass baseclass)
{
return new Derived(baseclass.name);
}
}
这行不通。为什么不允许?
我可能会编写必要的逻辑以使其有意义,尤其是在从基础转换为派生逻辑时。
编辑:更改了问题的标题