Search code examples
c#interfacestaticabstract-classoverriding

How can I assure a class to have a static property by using interface or abstract?


I have one abstract class -let's say myBase. And I want all the classes derived from myBase to have one static field called

public static List<string> MyPArameterNames 
{
get {return _myParameterNames;} 
}

So, every child class can tell what parameter names it uses; I want static because I do not want to create an instance just for this.

How can I achieve this?


Solution

  • You can't do that. Interfaces, abstract, etc. cannot apply to static members. If you want to accomplish this, you will have to manually remember to do it on all deriving classes.

    Also, static members are inherited by deriving classes. Child classes must hide the static parent member if they wish to specify alternate behavior.