我有一个抽象的 C# 基类,其中有几个必须重写的方法。我该如何执行?现在我抛出一个异常作为基本实现
public virtual string Description { get { throw new NotImplementedException(); } } public virtual string ErrorMessage { get { throw new NotImplementedException(); } }
但是,该解决方案感觉有点不对,而且非常不直观......是否有其他方法可以在 C# 中解决此问题?
最佳答案
创建属性(在您的示例中这些不是方法)abstract .
public abstract string Description{ get; }
public abstract string ErrorMessage{ get; }
关于c# - "Enforce"在 C# 中覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/897543/