"Enforce" redefines in C #

I have an abstract C # base class with several methods that need to be overridden. How can I provide this? Right now I'm throwing an exception as a base implementation

    public virtual string Description
    {
        get { throw new NotImplementedException(); }
    }

    public virtual string ErrorMessage
    {
        get { throw new NotImplementedException(); }
    }

This solution, however, is a bit erroneous and very little intuitive ... Are there other ways to solve this problem in C #?

+3
source share
2 answers

Make the properties (these are not the methods in your example) abstract .

public abstract string Description{ get; }

public abstract string ErrorMessage{ get; }
+16
source

In the case of a method, you must make them abstract

public abstract void Method();
+3
source

Source: https://habr.com/ru/post/1708889/


All Articles