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?
A private static field can be set from somewhere inside the interface. But a static method cannot be implemented from outside the interface since it is part of the interface itself.
Since you cannot instantiate a static class, static classes cannot implement interfaces.
NO, we can not inherit static class in c# because they are sealed and abstract. There seems to be no good reason to inherit a static class. It has public static members that you can always access via the class name itself. Any class which does not contain instance contructor, cannot be inherited.
You just specify that there is a property with a getter and a setter, whatever they will do. In the class, you actually implement them. The shortest way to do this is using this { get; set; } syntax. The compiler will create a field and generate the getter and setter implementation for it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With