我有一个抽象的基础C#类,有几个必须被覆盖的方法.我该如何强制执行此操作?现在我抛出异常作为基础实现
Run Code Online (Sandbox Code Playgroud)public virtual string Description { get { throw new NotImplementedException(); } } public virtual string ErrorMessage { get { throw new NotImplementedException(); } }
然而,这个解决方案感觉有点不对而且非常直观......有没有其他方法可以在C#中解决这个问题?
Win*_*ith 16
使属性(这些不是您的示例中的方法)抽象.
public abstract string Description{ get; }
public abstract string ErrorMessage{ get; }
Run Code Online (Sandbox Code Playgroud)