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

pencilCake picture pencilCake · Mar 14, 2010 · Viewed 28.4k times · Source

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?

Answer

Zach Johnson picture Zach Johnson · Mar 14, 2010

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.